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.
#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__
--- /dev/null
+/* 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
--- /dev/null
+/* 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);
+}