Skip to content

Commit 2442ef0

Browse files
authored
[DeviceSanitizer] Disable handling no return calls (#14652)
'__asan_handle_no_return' is used to unpoison stack before non return calls. And we didn't poison stack in device code, so we don't need to handle such case.
1 parent 03edba6 commit 2442ef0

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,10 +3466,14 @@ bool AddressSanitizer::instrumentFunction(Function &F,
34663466
NumInsnsPerBB++;
34673467
} else {
34683468
if (auto *CB = dyn_cast<CallBase>(&Inst)) {
3469-
// A call inside BB.
3470-
TempsToInstrument.clear();
3471-
if (CB->doesNotReturn())
3472-
NoReturnCalls.push_back(CB);
3469+
// On device side, the only non return cases should be *.trap or
3470+
// assert, and none of these cases need to be handles.
3471+
if (!TargetTriple.isSPIROrSPIRV()) {
3472+
// A call inside BB.
3473+
TempsToInstrument.clear();
3474+
if (CB->doesNotReturn())
3475+
NoReturnCalls.push_back(CB);
3476+
}
34733477
}
34743478
if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
34753479
if (TargetTriple.isSPIROrSPIRV() && CI->getCalledFunction() &&
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: opt < %s -passes=asan -asan-instrumentation-with-call-threshold=0 -asan-stack=0 -asan-globals=0 -asan-constructor-kind=none -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+
; Function Attrs: mustprogress nounwind sanitize_address uwtable
7+
define spir_func void @no_return(ptr addrspace(4) noundef align 8 dereferenceable_or_null(12) %this) unnamed_addr #0 {
8+
; CHECK-LABEL: @no_return
9+
; CHECK-NOT: call void @__asan_handle_no_return
10+
tail call void @llvm.trap() #1
11+
unreachable
12+
}
13+
14+
; Function Attrs: cold noreturn nounwind memory(inaccessiblemem: write)
15+
declare void @llvm.trap() #2
16+
17+
attributes #0 = { mustprogress nounwind sanitize_address uwtable }
18+
attributes #1 = { noreturn nounwind }
19+
attributes #2 = { cold noreturn nounwind memory(inaccessiblemem: write) }

0 commit comments

Comments
 (0)