[llvm] [TSan] Fix atomicrmw xchg with pointer and floats (PR #85228)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 14 14:24:32 PDT 2024


================
@@ -752,11 +752,12 @@ bool ThreadSanitizer::instrumentAtomic(Instruction *I, const DataLayout &DL) {
     const unsigned ByteSize = 1U << Idx;
     const unsigned BitSize = ByteSize * 8;
     Type *Ty = Type::getIntNTy(IRB.getContext(), BitSize);
-    Value *Args[] = {Addr,
-                     IRB.CreateIntCast(RMWI->getValOperand(), Ty, false),
+    Value *Val = RMWI->getValOperand();
+    Value *Args[] = {Addr, IRB.CreateBitOrPointerCast(Val, Ty),
                      createOrdering(&IRB, RMWI->getOrdering())};
-    CallInst *C = CallInst::Create(F, Args);
-    ReplaceInstWithInst(I, C);
+    Value *C = IRB.CreateCall(F, Args);
+    I->replaceAllUsesWith(IRB.CreateBitOrPointerCast(C, Val->getType()));
----------------
nikic wrote:

The reason I changed this is that we now go through IRBuilder, which will insert the instructions itself, so we can no longer use ReplaceInstWithInst. This is also why the cmpxchg code does the same.

https://github.com/llvm/llvm-project/pull/85228


More information about the llvm-commits mailing list