Skip to content

[Clang] Define __SIG_ATOMIC_TYPE__ macro - #213934

Merged
zeyi2 merged 1 commit into
llvm:mainfrom
zeyi2:acp/zeyi2/6968975185917331
Aug 5, 2026
Merged

[Clang] Define __SIG_ATOMIC_TYPE__ macro#213934
zeyi2 merged 1 commit into
llvm:mainfrom
zeyi2:acp/zeyi2/6968975185917331

Conversation

@zeyi2

@zeyi2 zeyi2 commented Aug 4, 2026

Copy link
Copy Markdown
Member

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 #199678, Closes #213895

@zeyi2
zeyi2 requested a review from AaronBallman August 4, 2026 13:22
@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category backend:RISC-V labels Aug 4, 2026
@llvmorg-github-actions

llvmorg-github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-clang

Author: Zeyi Xu (zeyi2)

Changes

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 #199678, Closes #213895


Full diff: https://github.com/llvm/llvm-project/pull/213934.diff

5 Files Affected:

  • (modified) clang/docs/ReleaseNotes.md (+1)
  • (modified) clang/lib/Frontend/InitPreprocessor.cpp (+1)
  • (modified) clang/test/Preprocessor/init-aarch64.c (+1)
  • (modified) clang/test/Preprocessor/init-riscv.c (+1)
  • (modified) clang/test/Preprocessor/init.c (+2)
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 compnerd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this seems good to me.

@AaronBallman AaronBallman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! This would be reasonable to backport to Clang 23.x, if needed (because system headers rely on it).

@zeyi2
zeyi2 merged commit c08ed4c into llvm:main Aug 5, 2026
16 checks passed
@zeyi2 zeyi2 added this to the LLVM 23.x Release milestone Aug 5, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in LLVM Release Status Aug 5, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in LLVM Release Status Aug 5, 2026
@zeyi2

zeyi2 commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

/cherry-pick c08ed4c

@llvmbot

llvmbot commented Aug 5, 2026

Copy link
Copy Markdown
Member

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

dyung pushed a commit to zeyi2/llvm-project that referenced this pull request Aug 6, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:RISC-V clang Clang issues not falling into any other category release:cherry-pick-failed

Projects

Development

Successfully merging this pull request may close these issues.

Clang does not define __SIG_ATOMIC_TYPE__ predefined macro

4 participants