Skip to content

Commit 4b14d70

Browse files
authored
[SYCL][DeviceSanitizer] Use -asan-constructor-kind=none to disable ctor/dtor (#13259)
The removed code fails to prevent ctor/dtor generation.
1 parent 4b819cc commit 4b14d70

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,10 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
11511151
CmdArgs.push_back("-mllvm");
11521152
CmdArgs.push_back("-asan-instrumentation-with-call-threshold=0");
11531153

1154+
// asan initialization is done in unified runtime rather than in ctor.
1155+
CmdArgs.push_back("-mllvm");
1156+
CmdArgs.push_back("-asan-constructor-kind=none");
1157+
11541158
CmdArgs.push_back("-mllvm");
11551159
CmdArgs.push_back("-asan-stack=0");
11561160
CmdArgs.push_back("-mllvm");

clang/test/Driver/sycl-device-sanitizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// SYCL-ASAN-SAME: -fsanitize-address-use-after-return=never
66
// SYCL-ASAN-SAME: -fno-sanitize-address-use-after-scope
77
// SYCL-ASAN-SAME: "-mllvm" "-asan-instrumentation-with-call-threshold=0"
8+
// SYCL-ASAN-SAME: "-mllvm" "-asan-constructor-kind=none"
89
// SYCL-ASAN-SAME: "-mllvm" "-asan-stack=0"
910
// SYCL-ASAN-SAME: "-mllvm" "-asan-globals=0"
1011

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,12 +2911,6 @@ bool ModuleAddressSanitizer::instrumentModule(Module &M) {
29112911
}
29122912
}
29132913

2914-
// SPIR kernel needn't AsanCtorFunction & AsanDtorFunction
2915-
if (TargetTriple.isSPIR()) {
2916-
AsanCtorFunction = nullptr;
2917-
AsanDtorFunction = nullptr;
2918-
}
2919-
29202914
const uint64_t Priority = GetCtorAndDtorPriority(TargetTriple);
29212915

29222916
// Put the constructor and destructor in comdat if both
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// REQUIRES: linux
2+
// RUN: %clangxx -fsycl-device-only -fno-sycl-early-optimizations -Xarch_device -fsanitize=address -emit-llvm %s -S -o %t.ll
3+
// RUN: FileCheck %s --input-file %t.ll
4+
5+
// Check asan ctor is not generated since device asan initialization is done in
6+
// unified runtime rather than in ctor.
7+
8+
// CHECK-NOT: asan.module_ctor
9+
10+
#include <sycl/sycl.hpp>
11+
12+
using namespace sycl;
13+
14+
int main() {
15+
sycl::queue queue;
16+
{
17+
queue.submit(
18+
[&](sycl::handler &cgh) { cgh.single_task<class t>([=]() {}); });
19+
queue.wait();
20+
}
21+
22+
return 0;
23+
}

0 commit comments

Comments
 (0)