public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Joseph Myers <jsm28@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2563] stddef.h: Add C2x unreachable macro Date: Fri, 9 Sep 2022 14:12:03 +0000 (GMT) [thread overview] Message-ID: <20220909141203.C2F32385701B@sourceware.org> (raw) https://gcc.gnu.org/g:a1a53dc7d87969d230e9ca51fcab59f3a72e5f6e commit r13-2563-ga1a53dc7d87969d230e9ca51fcab59f3a72e5f6e Author: Joseph Myers <joseph@codesourcery.com> Date: Fri Sep 9 14:11:21 2022 +0000 stddef.h: Add C2x unreachable macro C2x adds a macro unreachable to stddef.h, with the same semantics as __builtin_unreachable. Define this macro accordingly. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * ginclude/stddef.h [__STDC_VERSION__ > 201710L] (unreachable): New macro. gcc/testsuite/ * gcc.dg/c11-unreachable-1.c, gcc.dg/c2x-unreachable-1.c: New tests. Diff: --- gcc/ginclude/stddef.h | 4 ++++ gcc/testsuite/gcc.dg/c11-unreachable-1.c | 9 +++++++++ gcc/testsuite/gcc.dg/c2x-unreachable-1.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h index 315ff786694..3d29213e8f1 100644 --- a/gcc/ginclude/stddef.h +++ b/gcc/ginclude/stddef.h @@ -451,6 +451,10 @@ typedef struct { #endif #endif /* C23. */ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#define unreachable() (__builtin_unreachable ()) +#endif + #endif /* _STDDEF_H was defined this time */ #endif /* !_STDDEF_H && !_STDDEF_H_ && !_ANSI_STDDEF_H && !__STDDEF_H__ diff --git a/gcc/testsuite/gcc.dg/c11-unreachable-1.c b/gcc/testsuite/gcc.dg/c11-unreachable-1.c new file mode 100644 index 00000000000..28e48392ed1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-unreachable-1.c @@ -0,0 +1,9 @@ +/* Test unreachable not defined in <stddef.h> for C11. */ +/* { dg-do preprocess } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stddef.h> + +#ifdef unreachable +#error "unreachable defined" +#endif diff --git a/gcc/testsuite/gcc.dg/c2x-unreachable-1.c b/gcc/testsuite/gcc.dg/c2x-unreachable-1.c new file mode 100644 index 00000000000..468f1f87ebb --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-unreachable-1.c @@ -0,0 +1,29 @@ +/* Test unreachable in <stddef.h> for C2x. */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -pedantic-errors -O2" } */ + +#include <stddef.h> + +#ifndef unreachable +#error "unreachable not defined" +#endif + +extern void *p; +extern __typeof__ (unreachable ()) *p; + +volatile int x = 1; + +extern void not_defined (void); + +extern void exit (int); + +int +main () +{ + if (x == 2) + { + unreachable (); + not_defined (); + } + exit (0); +}
reply other threads:[~2022-09-09 14:12 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220909141203.C2F32385701B@sourceware.org \ --to=jsm28@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).