Skip to content

Commit 355725a

Browse files
authored
[TSan] Fix missing inst cleanup (#144067)
Commit 44e875a introduced a change that replaces `ReplaceInstWithInst` with `Instruction::replaceAllUsesWith`, without subsequent instruction cleanup. This results in TSan leaving behind useless `load atomic` instructions after 'replacing' them. This commit adds cleanup back, consistent with the context.
1 parent 43e1a5a commit 355725a

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ bool ThreadSanitizer::instrumentAtomic(Instruction *I, const DataLayout &DL) {
728728
Value *C = IRB.CreateCall(TsanAtomicLoad[Idx], Args);
729729
Value *Cast = IRB.CreateBitOrPointerCast(C, OrigTy);
730730
I->replaceAllUsesWith(Cast);
731+
I->eraseFromParent();
731732
} else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
732733
Value *Addr = SI->getPointerOperand();
733734
int Idx =

llvm/test/Instrumentation/ThreadSanitizer/atomic-non-integer.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ define float @load_float(ptr %fptr) {
1010
; CHECK-NEXT: call void @__tsan_func_entry(ptr [[TMP1]])
1111
; CHECK-NEXT: [[TMP2:%.*]] = call i32 @__tsan_atomic32_load(ptr [[FPTR]], i32 0)
1212
; CHECK-NEXT: [[TMP3:%.*]] = bitcast i32 [[TMP2]] to float
13-
; CHECK-NEXT: [[V:%.*]] = load atomic float, ptr [[FPTR]] unordered, align 4
1413
; CHECK-NEXT: call void @__tsan_func_exit()
1514
; CHECK-NEXT: ret float [[TMP3]]
1615
;
@@ -25,7 +24,6 @@ define double @load_double(ptr %fptr) {
2524
; CHECK-NEXT: call void @__tsan_func_entry(ptr [[TMP1]])
2625
; CHECK-NEXT: [[TMP2:%.*]] = call i64 @__tsan_atomic64_load(ptr [[FPTR]], i32 0)
2726
; CHECK-NEXT: [[TMP3:%.*]] = bitcast i64 [[TMP2]] to double
28-
; CHECK-NEXT: [[V:%.*]] = load atomic double, ptr [[FPTR]] unordered, align 8
2927
; CHECK-NEXT: call void @__tsan_func_exit()
3028
; CHECK-NEXT: ret double [[TMP3]]
3129
;
@@ -40,7 +38,6 @@ define fp128 @load_fp128(ptr %fptr) {
4038
; CHECK-NEXT: call void @__tsan_func_entry(ptr [[TMP1]])
4139
; CHECK-NEXT: [[TMP2:%.*]] = call i128 @__tsan_atomic128_load(ptr [[FPTR]], i32 0)
4240
; CHECK-NEXT: [[TMP3:%.*]] = bitcast i128 [[TMP2]] to fp128
43-
; CHECK-NEXT: [[V:%.*]] = load atomic fp128, ptr [[FPTR]] unordered, align 16
4441
; CHECK-NEXT: call void @__tsan_func_exit()
4542
; CHECK-NEXT: ret fp128 [[TMP3]]
4643
;

0 commit comments

Comments
 (0)