Skip to content

Commit 3d70234

Browse files
authored
[sycl-post-link] Update spec constant pattern match for Device ASan (#20680)
Address Sanitizer pass changed the way to get stack offset from PtrIntAdd to GEP instruction. We need to update the pattern match rule correspondingly.
1 parent ac28a83 commit 3d70234

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

llvm/lib/SYCLLowerIR/SpecConstants.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ StringRef getStringLiteralArg(const CallInst *CI, unsigned ArgNo,
122122
V = ASC->getPointerOperand()->stripPointerCasts();
123123
using namespace PatternMatch;
124124
Value *X;
125-
if (match(V, m_IntToPtr(m_Add(m_PtrToInt(m_Value(X)), m_ConstantInt()))))
125+
if (match(V, m_PtrAdd(m_Value(X), m_Constant())))
126126
V = X;
127127
return isa<AllocaInst>(V);
128128
};
@@ -541,7 +541,8 @@ Instruction *emitCall(Type *RetTy, StringRef BaseFunctionName,
541541
// types? Is it necessary?
542542

543543
FunctionCallee FC = M->getOrInsertFunction(FunctionName, FT);
544-
auto *Call = CallInst::Create(FT, FC.getCallee(), Args, "", InsertBefore);
544+
auto *Call = CallInst::Create(FT, FC.getCallee(), Args, "",
545+
InsertBefore->getIterator());
545546
if (IsSPIROrSPIRV) {
546547
cast<Function>(FC.getCallee())->setCallingConv(CallingConv::SPIR_FUNC);
547548
Call->setCallingConv(CallingConv::SPIR_FUNC);
@@ -724,9 +725,8 @@ Value *createLoadFromBuffer(CallInst *InsertBefore, Value *Buffer,
724725
if (SCType->isIntegerTy(1)) // No bitcast to i1 before load
725726
BitCast = GEP;
726727
else
727-
BitCast =
728-
new BitCastInst(GEP, PointerType::get(SCType, GEP->getAddressSpace()),
729-
"bc", InsertBefore->getIterator());
728+
BitCast = new BitCastInst(GEP, PointerType::get(C, GEP->getAddressSpace()),
729+
"bc", InsertBefore->getIterator());
730730

731731
// When we encounter i1 spec constant, we still load the whole byte
732732
Value *Load = new LoadInst(SCType->isIntegerTy(1) ? Int8Ty : SCType, BitCast,
@@ -831,8 +831,8 @@ void updatePaddingInLastMDNode(LLVMContext &Ctx,
831831
/// type.
832832
void createStoreInstructionIntoSpecConstValue(Value *Dst, Value *V,
833833
CallInst *InsertBefore) {
834-
Type *PointerType =
835-
PointerType::get(V->getType(), Dst->getType()->getPointerAddressSpace());
834+
Type *PointerType = PointerType::get(
835+
V->getContext(), Dst->getType()->getPointerAddressSpace());
836836
IRBuilder B(InsertBefore);
837837
Value *Bitcast = B.CreateBitCast(Dst, PointerType);
838838
B.CreateStore(V, Bitcast);

llvm/test/SYCLLowerIR/SpecConstants/literal-address-alloca-asan.ll

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,21 @@ target triple = "spir64-unknown-unknown"
99
%"class.sycl::_V1::specialization_id" = type { i32 }
1010

1111
@_ZL9test_id_1 = addrspace(1) constant %"class.sycl::_V1::specialization_id" { i32 42 }
12-
@__usid_str = constant [36 x i8] c"uide7faddc6b4d2fe92____ZL9test_id_1\00"
12+
@__usid_str = private unnamed_addr addrspace(4) constant [36 x i8] c"uide7faddc6b4d2fe92____ZL9test_id_1\00"
1313

1414
define spir_func void @_ZZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_ENKUlNS0_14kernel_handlerEE_clES4_(ptr addrspace(4) %this1.i7) {
1515
entry:
16-
%MyAlloca = alloca i8, i64 224, align 32
17-
%0 = ptrtoint ptr %MyAlloca to i64
18-
%1 = add i64 %0, 96
19-
%2 = inttoptr i64 %1 to ptr
20-
%SymbolicID.ascast.i = addrspacecast ptr %2 to ptr addrspace(4)
21-
store ptr addrspace(4) addrspacecast (ptr @__usid_str to ptr addrspace(4)), ptr addrspace(4) %SymbolicID.ascast.i, align 8
22-
%3 = load ptr addrspace(4), ptr addrspace(4) %SymbolicID.ascast.i, align 8
23-
%4 = load ptr addrspace(4), ptr addrspace(4) %this1.i7, align 8
16+
%MyAlloca = alloca [256 x i8], align 32
17+
%0 = getelementptr i8, ptr %MyAlloca, i64 96
18+
%SymbolicID.ascast.i = addrspacecast ptr %0 to ptr addrspace(4)
19+
store ptr addrspace(4) @__usid_str, ptr addrspace(4) %SymbolicID.ascast.i, align 8
20+
%1 = load ptr addrspace(4), ptr addrspace(4) %SymbolicID.ascast.i, align 8
21+
%2 = load ptr addrspace(4), ptr addrspace(4) %this1.i7, align 8
2422

2523
; CHECK-NOT: call spir_func noundef i32 @_Z37__sycl_getScalar2020SpecConstantValueIiET_PKcPKvS4_(
2624
; CHECK: %conv = sitofp i32 %load to double
2725

28-
%call.i8 = call spir_func i32 @_Z37__sycl_getScalar2020SpecConstantValueIiET_PKcPKvS4_(ptr addrspace(4) %3, ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZL9test_id_1 to ptr addrspace(4)), ptr addrspace(4) %4)
26+
%call.i8 = call spir_func i32 @_Z37__sycl_getScalar2020SpecConstantValueIiET_PKcPKvS4_(ptr addrspace(4) %1, ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZL9test_id_1 to ptr addrspace(4)), ptr addrspace(4) %2)
2927
%conv = sitofp i32 %call.i8 to double
3028
ret void
3129
}

0 commit comments

Comments
 (0)