Skip to content

Commit cb71841

Browse files
authored
[DeviceSanitizer] Disable ASan when the ESIMD kernel is found (#14156)
ESIMD kernel doesn't support noinline functions, so we can't support sanitizer for it now. We can't check if the kernel is ESIMD kernel at Unified Runtime, so we have to disable ASan completely when it found ESIMD kernel in device image.
1 parent 417cc1b commit cb71841

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,8 @@ struct FunctionStackPoisoner : public InstVisitor<FunctionStackPoisoner> {
12781278
static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM) {
12791279
SmallVector<Function *> SpirFixupFuncs;
12801280
for (Function &F : M) {
1281-
if (F.getCallingConv() == CallingConv::SPIR_KERNEL) {
1281+
if (F.getCallingConv() == CallingConv::SPIR_KERNEL &&
1282+
F.hasFnAttribute(Attribute::SanitizeAddress)) {
12821283
SpirFixupFuncs.emplace_back(&F);
12831284
}
12841285
}
@@ -1294,9 +1295,7 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM) {
12941295
Types.push_back(I->getType());
12951296
}
12961297

1297-
// New argument type: uintptr_t as(1)*, as it's allocated in USM buffer, and
1298-
// it can also be treated as a pointer point to the base address of private
1299-
// shadow memory
1298+
// New argument: uintptr_t as(1)*, which is allocated in shared USM buffer
13001299
Types.push_back(IntptrTy->getPointerTo(kSpirOffloadGlobalAS));
13011300

13021301
FunctionType *NewFTy = FunctionType::get(F->getReturnType(), Types, false);
@@ -1411,6 +1410,21 @@ PreservedAnalyses AddressSanitizerPass::run(Module &M,
14111410
ClUseStackSafety ? &MAM.getResult<StackSafetyGlobalAnalysis>(M) : nullptr;
14121411

14131412
if (Triple(M.getTargetTriple()).isSPIR()) {
1413+
bool HasESIMDKernel = false;
1414+
1415+
// ESIMD kernel doesn't support noinline functions, so we can't
1416+
// support sanitizer for it
1417+
for (Function &F : M)
1418+
if (F.hasMetadata("sycl_explicit_simd")) {
1419+
F.removeFnAttr(Attribute::SanitizeAddress);
1420+
HasESIMDKernel = true;
1421+
}
1422+
1423+
// FIXME: we can't check if the kernel is ESIMD kernel at UR, so we
1424+
// have to disable ASan completely in this case
1425+
if (HasESIMDKernel)
1426+
return PreservedAnalyses::all();
1427+
14141428
ExtendSpirKernelArgs(M, FAM);
14151429
}
14161430

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: opt < %s -passes=asan -asan-instrumentation-with-call-threshold=0 -asan-stack=0 -asan-globals=0 -S | FileCheck %s
2+
3+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
4+
target triple = "spir64-unknown-unknown"
5+
6+
@__spirv_BuiltInGlobalInvocationId = external addrspace(1) constant <3 x i64>
7+
8+
; Function Attrs: sanitize_address
9+
define spir_kernel void @esimd_kernel() #0 !sycl_explicit_simd !1 {
10+
entry:
11+
%0 = load i64, ptr addrspace(1) getelementptr inbounds (i8, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId, i64 8), align 8
12+
ret void
13+
}
14+
; CHECK-NOT: {{ sanitize_address }}
15+
16+
attributes #0 = { sanitize_address }
17+
!1 = !{}

0 commit comments

Comments
 (0)