[clang] 3652b2a - [clang][CodeGen][OpenMP] Fix casting of atomic update of ptr types (#88215)

via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 12 10:01:06 PDT 2024


Author: Mike Rice
Date: 2024-04-12T10:01:01-07:00
New Revision: 3652b2a877c3691b524a19bc38b338f1ba1dde37

URL: https://github.com/llvm/llvm-project/commit/3652b2a877c3691b524a19bc38b338f1ba1dde37
DIFF: https://github.com/llvm/llvm-project/commit/3652b2a877c3691b524a19bc38b338f1ba1dde37.diff

LOG: [clang][CodeGen][OpenMP] Fix casting of atomic update of ptr types (#88215)

In 4d5e834c5b7f0ccccd90a6d543e182df602f6bc8, casts were removed for
pointers but one case was missed. Add missing check.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGAtomic.cpp
    clang/test/OpenMP/atomic_update_codegen.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index d35ce0409d7232..07452b18a85ea4 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -1806,7 +1806,11 @@ void AtomicInfo::EmitAtomicUpdateOp(
                                              /*NumReservedValues=*/2);
   PHI->addIncoming(OldVal, CurBB);
   Address NewAtomicAddr = CreateTempAlloca();
-  Address NewAtomicIntAddr = castToAtomicIntPointer(NewAtomicAddr);
+  Address NewAtomicIntAddr =
+      shouldCastToInt(NewAtomicAddr.getElementType(), /*CmpXchg=*/true)
+          ? castToAtomicIntPointer(NewAtomicAddr)
+          : NewAtomicAddr;
+
   if ((LVal.isBitField() && BFI.Size != ValueSizeInBits) ||
       requiresMemSetZero(getAtomicAddress().getElementType())) {
     CGF.Builder.CreateStore(PHI, NewAtomicIntAddr);

diff  --git a/clang/test/OpenMP/atomic_update_codegen.cpp b/clang/test/OpenMP/atomic_update_codegen.cpp
index ce0765118922a1..fe745590a9f919 100644
--- a/clang/test/OpenMP/atomic_update_codegen.cpp
+++ b/clang/test/OpenMP/atomic_update_codegen.cpp
@@ -27,6 +27,7 @@ long double ldv, ldx;
 _Complex int civ, cix;
 _Complex float cfv, cfx;
 _Complex double cdv, cdx;
+char *cpx;
 
 typedef int int4 __attribute__((__vector_size__(16)));
 int4 int4x;
@@ -851,6 +852,16 @@ int main(void) {
 // CHECK: call{{.*}} @__kmpc_flush(
 #pragma omp atomic seq_cst
   rix = dv / rix;
+
+// CHECK: [[LD_CPX:%.+]] = load atomic ptr, ptr @cpx monotonic
+// CHECK: br label %[[CONT:.+]]
+// CHECK: [[CONT]]
+// CHECK: [[PHI:%.+]] = phi ptr
+// CHECK: [[RES:%.+]] = cmpxchg ptr @cpx,
+// CHECK: br i1 %{{.+}}, label %[[EXIT:.+]], label %[[CONT]]
+  #pragma omp atomic update
+  cpx += 1;
+
   return 0;
 }
 


        


More information about the cfe-commits mailing list