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

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 14 14:18:35 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()));
----------------
vitalybuka wrote:

Looks like `replaceAllUsesWith/eraseFromParent` matches `ReplaceInstWithInst`
However, could we keep code consistent?
Replacing all places in a separate patch LGTM.

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


More information about the llvm-commits mailing list