[clang] 8328966 - [PowerPC] Fix to guard fetch and cas 64-bit builtin versions

Kamau Bridgeman via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 4 12:45:41 PDT 2021


Author: Kamau Bridgeman
Date: 2021-10-04T14:45:36-05:00
New Revision: 83289665200b6b9212e0ff14e274b2c431a2e1fa

URL: https://github.com/llvm/llvm-project/commit/83289665200b6b9212e0ff14e274b2c431a2e1fa
DIFF: https://github.com/llvm/llvm-project/commit/83289665200b6b9212e0ff14e274b2c431a2e1fa.diff

LOG: [PowerPC] Fix to guard fetch and cas 64-bit builtin versions

The builtins: `__compare_and_swaplp`, `__fetch_and_addlp`,
` __fetch_and_andlp`, `__fetch_and_orlp`, `__fetch_and_swaplp` are
64 bit only. This patch ensures the compiler produces an error in 32 bit mode.

Reviewed By: #powerpc, nemanjai

Differential Revision: https://reviews.llvm.org/D110824

Added: 
    

Modified: 
    clang/lib/Sema/SemaChecking.cpp
    clang/test/CodeGen/builtins-ppc-xlcompat-error.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 207b28ec5972..a6d26ac65465 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3297,6 +3297,11 @@ static bool isPPC_64Builtin(unsigned BuiltinID) {
   case PPC::BI__builtin_ppc_addex:
   case PPC::BI__builtin_darn:
   case PPC::BI__builtin_darn_raw:
+  case PPC::BI__builtin_ppc_compare_and_swaplp:
+  case PPC::BI__builtin_ppc_fetch_and_addlp:
+  case PPC::BI__builtin_ppc_fetch_and_andlp:
+  case PPC::BI__builtin_ppc_fetch_and_orlp:
+  case PPC::BI__builtin_ppc_fetch_and_swaplp:
     return true;
   }
   return false;

diff  --git a/clang/test/CodeGen/builtins-ppc-xlcompat-error.c b/clang/test/CodeGen/builtins-ppc-xlcompat-error.c
index f1c577cf846f..9fc218b1de41 100644
--- a/clang/test/CodeGen/builtins-ppc-xlcompat-error.c
+++ b/clang/test/CodeGen/builtins-ppc-xlcompat-error.c
@@ -104,6 +104,25 @@ int test_darn() {
 int test_darn_raw() {
   return __darn_raw(); //expected-error {{this builtin is only available on 64-bit targets}}
 }
+
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_addlp(long a, long b) {
+  __fetch_and_addlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_andlp(unsigned long a, unsigned long b) {
+  __fetch_and_andlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+void test_builtin_ppc_fetch_and_orlp(unsigned long a, unsigned long b) {
+  __fetch_and_orlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_swaplp(unsigned long a, unsigned long b) {
+  __fetch_and_swaplp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
 #endif
 
 unsigned long test_mfspr(void) {


        


More information about the cfe-commits mailing list