Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
I->eraseFromParent();
} else if (AtomicCmpXchgInst *CASI = dyn_cast<AtomicCmpXchgInst>(I)) {
Value *Addr = CASI->getPointerOperand();
Type *OrigOldValTy = CASI->getNewValOperand()->getType();
Expand Down
20 changes: 20 additions & 0 deletions llvm/test/Instrumentation/ThreadSanitizer/atomic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ entry:
; CHECK-LABEL: atomic8_xchg_monotonic
; CHECK: call i8 @__tsan_atomic8_exchange(ptr %a, i8 0, i32 0), !dbg

define void @atomic8_xchg_monotonic_ptr(ptr %a, ptr %b) nounwind uwtable {
entry:
atomicrmw xchg ptr %a, ptr %b monotonic, !dbg !7
ret void, !dbg !7
}
; CHECK-LABEL: atomic8_xchg_monotonic_ptr
; CHECK: [[ARG:%.*]] = ptrtoint ptr %b to i64, !dbg
; CHECK: [[RES:%.*]] = call i64 @__tsan_atomic64_exchange(ptr %a, i64 [[ARG]], i32 0), !dbg
; CHECK: [[CAST:%.*]] = inttoptr i64 [[RES]] to ptr, !dbg

define void @atomic8_xchg_monotonic_float(ptr %a, float %b) nounwind uwtable {
entry:
atomicrmw xchg ptr %a, float %b monotonic, !dbg !7
ret void, !dbg !7
}
; CHECK-LABEL: atomic8_xchg_monotonic_float
; CHECK: [[ARG:%.*]] = bitcast float %b to i32, !dbg
; CHECK: [[RES:%.*]] = call i32 @__tsan_atomic32_exchange(ptr %a, i32 [[ARG]], i32 0), !dbg
; CHECK: [[CAST:%.*]] = bitcast i32 [[RES]] to float, !dbg

define void @atomic8_add_monotonic(ptr %a) nounwind uwtable {
entry:
atomicrmw add ptr %a, i8 0 monotonic, !dbg !7
Expand Down