[clang] [clang][CodeGen][OpenMP] Fix casting of atomic update of ptr types (PR #88215)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 9 16:50:45 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: Mike Rice (mikerice1969)
<details>
<summary>Changes</summary>
In 4d5e834c5b7f0ccccd90a6d543e182df602f6bc8, casts were removed for pointers but one case was missed. Add missing check.
---
Full diff: https://github.com/llvm/llvm-project/pull/88215.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGAtomic.cpp (+5-1)
- (modified) clang/test/OpenMP/atomic_update_codegen.cpp (+11)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/88215
More information about the cfe-commits
mailing list