[libc-commits] [libc] 4010e0c - [libc] Use __attribute__((__noreturn__)) for _Noreturn in C < 11 (#121252)
via libc-commits
libc-commits at lists.llvm.org
Thu Jan 2 16:57:34 PST 2025
Author: Roland McGrath
Date: 2025-01-02T16:57:31-08:00
New Revision: 4010e0c45b87e4d073c407cae787e96d4808ad36
URL: https://github.com/llvm/llvm-project/commit/4010e0c45b87e4d073c407cae787e96d4808ad36
DIFF: https://github.com/llvm/llvm-project/commit/4010e0c45b87e4d073c407cae787e96d4808ad36.diff
LOG: [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.
Added:
Modified:
libc/include/__llvm-libc-common.h
Removed:
################################################################################
diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index d54ee7b9f91f32..d9d70aff771c08 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -52,6 +52,16 @@
#undef __restrict
#define __restrict restrict // C99 and above support the restrict keyword.
+#undef _Noreturn
+#if __STDC_VERSION__ >= 201112L
+// In C11 and later, _Noreturn is a keyword.
+#elif defined(__GNUC__)
+// GNU-compatible compilers have an equivalent attribute.
+#define _Noreturn __attribute__((__noreturn__))
+#else
+#define _Noreturn
+#endif
+
#undef __NOEXCEPT
#ifdef __GNUC__
#define __NOEXCEPT __attribute__((__nothrow__))
More information about the libc-commits
mailing list