diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -124,6 +124,8 @@ C2x Feature Support ------------------- +- Implemented the ``unreachable`` macro in freestanding ```` for + `WG14 N2826 `_ C++ Language Changes in Clang ----------------------------- diff --git a/clang/lib/Headers/stddef.h b/clang/lib/Headers/stddef.h --- a/clang/lib/Headers/stddef.h +++ b/clang/lib/Headers/stddef.h @@ -103,6 +103,11 @@ typedef typeof(nullptr) nullptr_t; #endif /* defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L */ +#if defined(__need_STDDEF_H_misc) && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 202000L +#define unreachable() __builtin_unreachable() +#endif /* defined(__need_STDDEF_H_misc) && >= C23 */ + #if defined(__need_STDDEF_H_misc) #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ (defined(__cplusplus) && __cplusplus >= 201103L) diff --git a/clang/test/C/C2x/n2826.c b/clang/test/C/C2x/n2826.c new file mode 100644 --- /dev/null +++ b/clang/test/C/C2x/n2826.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -ffreestanding -emit-llvm -o - -std=c2x %s | FileCheck %s +// RUN: %clang_cc1 -ffreestanding -std=c17 -verify %s + +/* WG14 N2826: Clang 17 + * Add annotations for unreachable control flow v2 + */ +#include + +enum E { + Zero, + One, + Two, +}; + +int test(enum E e) { + switch (e) { + case Zero: return 0; + case One: return 1; + case Two: return 2; + } + unreachable(); // expected-error {{call to undeclared function 'unreachable'}} +} + +// CHECK: switch i32 %0, label %[[EPILOG:.+]] [ +// CHECK: [[EPILOG]]: +// CHECK-NEXT: unreachable diff --git a/clang/www/c_status.html b/clang/www/c_status.html --- a/clang/www/c_status.html +++ b/clang/www/c_status.html @@ -1028,7 +1028,7 @@ Add annotations for unreachable control flow v2 N2826 - No + Clang 17 Unicode Sequences More Than 21 Bits are a Constraint Violation r0