Skip to content

Commit e296856

Browse files
authored
[DevTSAN] Don't insert cleanup instruction for dynamic allocas (#18090)
For dynamic allocas, sometime it will not dominate exit BB, we need to skip them.
1 parent c17f4ef commit e296856

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ bool ThreadSanitizerOnSpirv::instrumentAllocInst(
323323
InstrumentationIRBuilder::ensureDebugInfo(*AtExit, *F);
324324
for (auto *Inst : AllocaInsts) {
325325
AllocaInst *AI = cast<AllocaInst>(Inst);
326+
// For dynamic allocas, sometime it will not dominate exit BB, we need to
327+
// skip them.
328+
if (!AI->isStaticAlloca())
329+
continue;
330+
326331
if (auto AllocSize = AI->getAllocationSize(DL)) {
327332
AtExit->CreateCall(
328333
TsanCleanupPrivate,

llvm/test/Instrumentation/ThreadSanitizer/SPIRV/cleanup_private_shadow.ll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,24 @@ target triple = "spir64-unknown-unknown"
55
%"class.sycl::_V1::range" = type { %"class.sycl::_V1::detail::array" }
66
%"class.sycl::_V1::detail::array" = type { [1 x i64] }
77

8-
define spir_kernel void @test() {
8+
%struct.Dimensions = type { i32, i32, i32, i32, i32, i32 }
9+
10+
define spir_kernel void @test(i32 %val) {
911
entry:
1012
%agg.tmp = alloca %"class.sycl::_V1::range", align 8
13+
%cmp = icmp eq i32 %val, 1
14+
br i1 %cmp, label %for.body.preheader, label %exit
15+
16+
for.body.preheader: ; preds = %entry
17+
br label %for.body
18+
19+
for.body: ; preds = %for.body.preheader
20+
%device-byval-temp.ascast234298 = alloca %struct.Dimensions, i32 0, align 8, addrspace(4)
21+
br label %exit
22+
23+
exit:
1124
; CHECK: [[REG1:%[0-9]+]] = ptrtoint ptr %agg.tmp to i64
1225
; CHECK-NEXT: call void @__tsan_cleanup_private(i64 [[REG1]], i32 8)
26+
; CHECK-NOT: ptrtoint ptr %device-byval-temp.ascast234298 to i64
1327
ret void
1428
}

0 commit comments

Comments
 (0)