Skip to content

Commit 3652b2a

Browse files
authored
[clang][CodeGen][OpenMP] Fix casting of atomic update of ptr types (#88215)
In 4d5e834, casts were removed for pointers but one case was missed. Add missing check.
1 parent 54a6798 commit 3652b2a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/CodeGen/CGAtomic.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,11 @@ void AtomicInfo::EmitAtomicUpdateOp(
18061806
/*NumReservedValues=*/2);
18071807
PHI->addIncoming(OldVal, CurBB);
18081808
Address NewAtomicAddr = CreateTempAlloca();
1809-
Address NewAtomicIntAddr = castToAtomicIntPointer(NewAtomicAddr);
1809+
Address NewAtomicIntAddr =
1810+
shouldCastToInt(NewAtomicAddr.getElementType(), /*CmpXchg=*/true)
1811+
? castToAtomicIntPointer(NewAtomicAddr)
1812+
: NewAtomicAddr;
1813+
18101814
if ((LVal.isBitField() && BFI.Size != ValueSizeInBits) ||
18111815
requiresMemSetZero(getAtomicAddress().getElementType())) {
18121816
CGF.Builder.CreateStore(PHI, NewAtomicIntAddr);

clang/test/OpenMP/atomic_update_codegen.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ long double ldv, ldx;
2727
_Complex int civ, cix;
2828
_Complex float cfv, cfx;
2929
_Complex double cdv, cdx;
30+
char *cpx;
3031

3132
typedef int int4 __attribute__((__vector_size__(16)));
3233
int4 int4x;
@@ -851,6 +852,16 @@ int main(void) {
851852
// CHECK: call{{.*}} @__kmpc_flush(
852853
#pragma omp atomic seq_cst
853854
rix = dv / rix;
855+
856+
// CHECK: [[LD_CPX:%.+]] = load atomic ptr, ptr @cpx monotonic
857+
// CHECK: br label %[[CONT:.+]]
858+
// CHECK: [[CONT]]
859+
// CHECK: [[PHI:%.+]] = phi ptr
860+
// CHECK: [[RES:%.+]] = cmpxchg ptr @cpx,
861+
// CHECK: br i1 %{{.+}}, label %[[EXIT:.+]], label %[[CONT]]
862+
#pragma omp atomic update
863+
cpx += 1;
864+
854865
return 0;
855866
}
856867

0 commit comments

Comments
 (0)