[libc-commits] [libc] [libc] Use __attribute__((__noreturn__)) for _Noreturn in C < 11 (PR #121252)
Roland McGrath via libc-commits
libc-commits at lists.llvm.org
Fri Dec 27 23:08:02 PST 2024
https://github.com/frobtech created https://github.com/llvm/llvm-project/pull/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.
>From dfce992ea80572368a112545697ad84ec2a7dcd3 Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Fri, 27 Dec 2024 23:05:17 -0800
Subject: [PATCH] [libc] Use __attribute__((__noreturn__)) for _Noreturn in C <
11
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.
---
libc/include/__llvm-libc-common.h | 10 ++++++++++
1 file changed, 10 insertions(+)
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