Skip to content

Commit 56ea8b2

Browse files
zhaomaosujsji
authored andcommitted
[DevASAN] Fix addrspace mismatch issue caused by pulldown (#32824)
JIRA: CMPLRLLVM-71162
1 parent 7aac90e commit 56ea8b2

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4566,19 +4566,22 @@ void FunctionStackPoisoner::processStaticAllocas() {
45664566
LocalStackBaseAlloca = LocalStackBase;
45674567
}
45684568

4569+
const auto &TargetTriple = Triple(F.getParent()->getTargetTriple());
4570+
45694571
// Replace Alloca instructions with base+offset.
45704572
SmallVector<Value *> NewAllocaPtrs;
45714573
for (const auto &Desc : SVD) {
45724574
AllocaInst *AI = Desc.AI;
45734575
replaceDbgDeclare(AI, LocalStackBaseAlloca, DIB, DIExprFlags, Desc.Offset);
45744576
Value *NewAllocaPtr = IRB.CreatePtrAdd(
45754577
LocalStackBase, ConstantInt::get(IntptrTy, Desc.Offset));
4578+
NewAllocaPtr = TargetTriple.isSPIROrSPIRV()
4579+
? IRB.CreateAddrSpaceCast(NewAllocaPtr, AI->getType())
4580+
: NewAllocaPtr;
45764581
AI->replaceAllUsesWith(NewAllocaPtr);
45774582
NewAllocaPtrs.push_back(NewAllocaPtr);
45784583
}
45794584

4580-
const auto &TargetTriple = Triple(F.getParent()->getTargetTriple());
4581-
45824585
// The left-most redzone has enough space for at least 4 pointers.
45834586
// SPIRV doesn't use the following metadata
45844587
if (!TargetTriple.isSPIROrSPIRV()) {

llvm/test/Instrumentation/AddressSanitizer/SPIRV/byval_arg.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ target triple = "spir64-unknown-unknown"
88
; Function Attrs: sanitize_address
99
define spir_func void @test(ptr addrspace(4) byval(%struct.Input) %input) #0 {
1010
entry:
11-
; CHECK: inttoptr i64 %1 to ptr addrspace(4)
11+
; CHECK: [[REG1:%[0-9]+]] = getelementptr i8, ptr %MyAlloca
12+
; CHECK: [[REG2:%[0-9]+]] = addrspacecast ptr [[REG1]] to ptr addrspace(4)
13+
; CHECK: call void @llvm.memcpy.p4.p4.i64(ptr addrspace(4) align 4 [[REG2]], ptr addrspace(4) align 4 %input, i64 44, i1 false)
1214
ret void
1315
}
1416

llvm/test/Instrumentation/AddressSanitizer/SPIRV/instrument_private_address_space.ll

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ define spir_kernel void @kernel() #0 {
2020
; CHECK-LABEL: define spir_kernel void @kernel
2121
entry:
2222
%p.i = alloca [4 x i32], align 4
23-
; CHECK: %shadow_ptr = call i64 @__asan_mem_to_shadow(i64 %0, i32 0)
24-
; CHECK: call void @__asan_set_shadow_private(i64 %4, i64 2, i8 -15)
25-
; CHECK: call void @__asan_set_shadow_private(i64 %5, i64 1, i8 -13)
23+
; CHECK: %shadow_ptr = call i64 @__asan_mem_to_shadow
24+
; CHECK: [[REG1:%[0-9]+]] = add i64 %shadow_ptr, 0
25+
; CHECK: call void @__asan_set_shadow_private(i64 [[REG1]], i64 2, i8 -15)
26+
; CHECK: [[REG2:%[0-9]+]] = add i64 %shadow_ptr, 3
27+
; CHECK: call void @__asan_set_shadow_private(i64 [[REG2]], i64 1, i8 -13)
2628
call void @llvm.lifetime.start.p0(ptr nonnull %p.i)
2729
call void @llvm.memcpy.p0.p1.i64(ptr align 4 %p.i, ptr addrspace(1) align 4 @__const._ZZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_ENKUlvE_clEv.p, i64 16, i1 false)
2830
%arraydecay.i = getelementptr inbounds [4 x i32], ptr %p.i, i64 0, i64 0
2931
%0 = addrspacecast ptr %arraydecay.i to ptr addrspace(4)
3032
%call.i = call spir_func i32 @_Z3fooPii(ptr addrspace(4) %0)
31-
; CHECK: call void @__asan_set_shadow_private(i64 %7, i64 2, i8 0)
32-
; CHECK: call void @__asan_set_shadow_private(i64 %8, i64 1, i8 0)
33+
; CHECK: [[REG3:%[0-9]+]] = add i64 %shadow_ptr, 0
34+
; CHECK: call void @__asan_set_shadow_private(i64 [[REG3]], i64 2, i8 0)
35+
; CHECK: [[REG4:%[0-9]+]] = add i64 %shadow_ptr, 3
36+
; CHECK: call void @__asan_set_shadow_private(i64 [[REG4]], i64 1, i8 0)
3337
ret void
3438
}
3539

0 commit comments

Comments
 (0)