Skip to content

Commit 4010e0c

Browse files
authored
[libc] Use __attribute__((__noreturn__)) for _Noreturn in C < 11 (#121252)
When in modes like C99, the _Noreturn keyword is not available in C. But GNU-compatible compilers have a `noreturn` attribute with the same effect on function declarations.
1 parent 3cac26f commit 4010e0c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

libc/include/__llvm-libc-common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@
5252
#undef __restrict
5353
#define __restrict restrict // C99 and above support the restrict keyword.
5454

55+
#undef _Noreturn
56+
#if __STDC_VERSION__ >= 201112L
57+
// In C11 and later, _Noreturn is a keyword.
58+
#elif defined(__GNUC__)
59+
// GNU-compatible compilers have an equivalent attribute.
60+
#define _Noreturn __attribute__((__noreturn__))
61+
#else
62+
#define _Noreturn
63+
#endif
64+
5565
#undef __NOEXCEPT
5666
#ifdef __GNUC__
5767
#define __NOEXCEPT __attribute__((__nothrow__))

0 commit comments

Comments
 (0)