[Clang] Define __SIG_ATOMIC_TYPE__ macro - #213934
Conversation
|
@llvm/pr-subscribers-backend-risc-v @llvm/pr-subscribers-clang Author: Zeyi Xu (zeyi2) ChangesDefine This fixes Reference: https://gcc.gnu.org/onlinedocs/gcc-16.1.0/cpp/Common-Predefined-Macros.html Follow up of #199678, Closes #213895 Full diff: https://github.com/llvm/llvm-project/pull/213934.diff 5 Files Affected:
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index a38b99ff8e075..7ea46cbf2aeed 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -365,6 +365,7 @@ features cannot lower the translation-unit ABI level;
- Fixed a bug where `__func__`, `__PRETTY_FUNCTION__` and `__FUNCTION__` were not resolving to the proper function when inside a lambda return type (#GH211811)
- Fixed USR generation for declarations whose signature mentions a class-type
non-type template parameter. (#GH212351)
+- Clang now defines the GCC-compatible predefined macro `__SIG_ATOMIC_TYPE__`. (#GH213895)
#### Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 8b6ff844d0daa..65b065dc818f5 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1191,6 +1191,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
DefineFmt(LangOpts, "__SIZE", TI.getSizeType(), TI, Builder);
DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
+ DefineType("__SIG_ATOMIC_TYPE__", TI.getSigAtomicType(), Builder);
DefineTypeSizeAndWidth("__SIG_ATOMIC", TI.getSigAtomicType(), TI, Builder);
DefineTypeMin("__SIG_ATOMIC", TI.getSigAtomicType(), TI, Builder);
if (LangOpts.C23)
diff --git a/clang/test/Preprocessor/init-aarch64.c b/clang/test/Preprocessor/init-aarch64.c
index 6796cb3bdd912..44b92ea2331b0 100644
--- a/clang/test/Preprocessor/init-aarch64.c
+++ b/clang/test/Preprocessor/init-aarch64.c
@@ -264,6 +264,7 @@
// AARCH64-NEXT: #define __SHRT_WIDTH__ 16
// AARCH64-NEXT: #define __SIG_ATOMIC_MAX__ 2147483647
// AARCH64-NEXT: #define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
+// AARCH64-NEXT: #define __SIG_ATOMIC_TYPE__ int
// AARCH64-NEXT: #define __SIG_ATOMIC_WIDTH__ 32
// AARCH64-NEXT: #define __SIZEOF_DOUBLE__ 8
// AARCH64-NEXT: #define __SIZEOF_FLOAT__ 4
diff --git a/clang/test/Preprocessor/init-riscv.c b/clang/test/Preprocessor/init-riscv.c
index 00282e670a0f7..ad554e6948a87 100644
--- a/clang/test/Preprocessor/init-riscv.c
+++ b/clang/test/Preprocessor/init-riscv.c
@@ -14,5 +14,6 @@
// RV64: #define __GCC_DESTRUCTIVE_SIZE 64
// NETBSD: #define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
+// NETBSD: #define __SIG_ATOMIC_TYPE__ int
// NETBSD: #define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)
// NETBSD: #define __WINT_MIN__ 0U
diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 249b01b619cdb..21d61de8c0aaf 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1950,9 +1950,11 @@
// WEBASSEMBLY-NEXT:#define __SHRT_WIDTH__ 16
// WEBASSEMBLY32-NEXT:#define __SIG_ATOMIC_MAX__ 2147483647L
// WEBASSEMBLY32-NEXT:#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
+// WEBASSEMBLY32-NEXT:#define __SIG_ATOMIC_TYPE__ long int
// WEBASSEMBLY32-NEXT:#define __SIG_ATOMIC_WIDTH__ 32
// WEBASSEMBLY64-NEXT:#define __SIG_ATOMIC_MAX__ 9223372036854775807L
// WEBASSEMBLY64-NEXT:#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
+// WEBASSEMBLY64-NEXT:#define __SIG_ATOMIC_TYPE__ long int
// WEBASSEMBLY64-NEXT:#define __SIG_ATOMIC_WIDTH__ 64
// WEBASSEMBLY-NEXT:#define __SIZEOF_DOUBLE__ 8
// WEBASSEMBLY-NEXT:#define __SIZEOF_FLOAT__ 4
|
compnerd
left a comment
There was a problem hiding this comment.
Thanks, this seems good to me.
AaronBallman
left a comment
There was a problem hiding this comment.
LGTM! This would be reasonable to backport to Clang 23.x, if needed (because system headers rely on it).
|
/cherry-pick c08ed4c |
|
Failed to cherry-pick: c08ed4c https://github.com/llvm/llvm-project/actions/runs/30978960770 Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request |
Define `__SIG_ATOMIC_TYPE__` for compatibility with GCC. This fixes `riscv32-netbsd` and `riscv64-netbsd` system headers that define `sig_atomic_t` using this macro. Reference: https://gcc.gnu.org/onlinedocs/gcc-16.1.0/cpp/Common-Predefined-Macros.html Follow up of llvm#199678, Closes llvm#213895 (cherry picked from commit c08ed4c)
Define
__SIG_ATOMIC_TYPE__for compatibility with GCC.This fixes
riscv32-netbsdandriscv64-netbsdsystem headers that definesig_atomic_tusing this macro.Reference: https://gcc.gnu.org/onlinedocs/gcc-16.1.0/cpp/Common-Predefined-Macros.html
Follow up of #199678, Closes #213895