Skip to content

Conversation

@bzEq
Copy link
Collaborator

@bzEq bzEq commented Dec 20, 2023

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.

@llvmbot llvmbot added clang Clang issues not falling into any other category compiler-rt clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Dec 20, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 20, 2023

@llvm/pr-subscribers-clang

Author: Kai Luo (bzEq)

Changes

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.


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

3 Files Affected:

  • (modified) clang/lib/Basic/Targets/OSTargets.h (+1-3)
  • (modified) clang/test/Preprocessor/init-ppc.c (-2)
  • (modified) compiler-rt/lib/builtins/CMakeLists.txt (+1-1)
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 
@bzEq bzEq requested a review from xingxue-ibm December 20, 2023 08:43
Copy link
Member

@daltenty daltenty left a comment

Choose a reason for hiding this comment

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

Last time I tested this functionality, we had some deadlocks if the standard library interfaces were used, which was part of the motivation for leaving this macro in.

It's possible the situation has changed since, but I'd like to confirm that first before we go ahead with removing the macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category compiler-rt

4 participants