diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp --- a/clang/lib/Basic/Targets/LoongArch.cpp +++ b/clang/lib/Basic/Targets/LoongArch.cpp @@ -158,6 +158,12 @@ } else if (ABI == "lp64s" || ABI == "ilp32s") { Builder.defineMacro("__loongarch_soft_float"); } + + Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1"); + Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2"); + Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"); + if (GRLen == 64) + Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8"); } static constexpr Builtin::Info BuiltinInfo[] = { diff --git a/clang/test/Preprocessor/init-loongarch.c b/clang/test/Preprocessor/init-loongarch.c --- a/clang/test/Preprocessor/init-loongarch.c +++ b/clang/test/Preprocessor/init-loongarch.c @@ -81,6 +81,9 @@ // LA32: #define __GCC_ATOMIC_SHORT_LOCK_FREE 2 // LA32: #define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 // LA32: #define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 +// LA32: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 +// LA32: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 +// LA32: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 // LA32: #define __ILP32__ 1 // LA32: #define __INT16_C_SUFFIX__ // LA32: #define __INT16_FMTd__ "hd" @@ -394,6 +397,10 @@ // LA64: #define __GCC_ATOMIC_SHORT_LOCK_FREE 2 // LA64: #define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 // LA64: #define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 +// LA64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 +// LA64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 +// LA64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 +// LA64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 // LA64: #define __INT16_C_SUFFIX__ // LA64: #define __INT16_FMTd__ "hd" // LA64: #define __INT16_FMTi__ "hi" diff --git a/clang/test/Preprocessor/predefined-arch-macros.c b/clang/test/Preprocessor/predefined-arch-macros.c --- a/clang/test/Preprocessor/predefined-arch-macros.c +++ b/clang/test/Preprocessor/predefined-arch-macros.c @@ -4372,3 +4372,20 @@ // CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 // CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 // CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 + +// Begin LoongArch tests ---------------- + +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: --target=loongarch32-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_LA32_ATOMICS +// CHECK_LA32_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 +// CHECK_LA32_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 +// CHECK_LA32_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 + +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: --target=loongarch64-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_LA64_ATOMICS +// CHECK_LA64_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 +// CHECK_LA64_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 +// CHECK_LA64_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 +// CHECK_LA64_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1