[compiler-rt] [clang] [AIX] Undefine __STDC_NO_ATOMICS__ to enable c11 atomics functionality (PR #76025)

Kai Luo via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 20 00:42:02 PST 2023


https://github.com/bzEq created https://github.com/llvm/llvm-project/pull/76025

This is copied from https://reviews.llvm.org/D109139.

`__STDC_NO_ATOMICS__` is predefined to indicate clang on AIX doesn't support `_Atomic` and not shipped with `stdatomic.h` yet. Actually `_Atomic` is already supported. For `stdatomic.h`, clang has implemented one in `clang/lib/Headers/stdatomic.h`.

For missing libc implementations,
```
atomic_flag_test_and_set
atomic_flag_test_and_set_explicit
atomic_flag_clear
atomic_flag_clear_explicit
atomic_thread_fence
atomic_signal_fence
```
Provide them via compiler-rt.

>From 326b21d8e822f52733388d411a06cc85109a3208 Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail at cn.ibm.com>
Date: Wed, 20 Dec 2023 08:38:40 +0000
Subject: [PATCH] Undefine __STDC_NO_ATOMICS__ to enable c11 atomics
 functionality

---
 clang/lib/Basic/Targets/OSTargets.h     | 4 +---
 clang/test/Preprocessor/init-ppc.c      | 2 --
 compiler-rt/lib/builtins/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 342af4bbc42b7b..f76afad947cb7f 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -645,10 +645,8 @@ class AIXTargetInfo : public OSTargetInfo<Target> {
     Builder.defineMacro("__TOS_AIX__");
     Builder.defineMacro("__HOS_AIX__");
 
-    if (Opts.C11) {
-      Builder.defineMacro("__STDC_NO_ATOMICS__");
+    if (Opts.C11)
       Builder.defineMacro("__STDC_NO_THREADS__");
-    }
 
     if (Opts.EnableAIXExtendedAltivecABI)
       Builder.defineMacro("__EXTABI__");
diff --git a/clang/test/Preprocessor/init-ppc.c b/clang/test/Preprocessor/init-ppc.c
index 3fb642af9d7420..8cdb2c6d3d350d 100644
--- a/clang/test/Preprocessor/init-ppc.c
+++ b/clang/test/Preprocessor/init-ppc.c
@@ -756,11 +756,9 @@
 // RUN: %clang_cc1 -x c -std=c11 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-STDC %s
 // RUN: %clang_cc1 -x c -std=gnu11 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-STDC %s
 // RUN: %clang_cc1 -x c -std=c17 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-STDC %s
-// PPC-AIX-STDC:#define __STDC_NO_ATOMICS__ 1
 // PPC-AIX-STDC:#define __STDC_NO_THREADS__ 1
 
 // RUN: %clang_cc1 -x c -std=c99 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-STDC-N %s
-// PPC-AIX-STDC-N-NOT:#define __STDC_NO_ATOMICS__ 1
 // PPC-AIX-STDC-N-NOT:#define __STDC_NO_THREADS__ 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -mlong-double-64 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-LD64 %s
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index e5b52db175d960..f57cd36eccd453 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -243,7 +243,7 @@ if(COMPILER_RT_HAS_ATOMIC_KEYWORD AND NOT COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN)
   )
 endif()
 
-if(APPLE)
+if(APPLE OR OS_NAME MATCHES "AIX")
   set(GENERIC_SOURCES
     ${GENERIC_SOURCES}
     atomic_flag_clear.c



More information about the cfe-commits mailing list