Skip to content

Commit 55416ca

Browse files
authored
[DeviceSanitizers] Set names to nameless globals (#17599)
DeviceSanitizer cannot handle nameless globals, but we cannot skip instrumenting them either. Therefore, we set names to nameless globals and process them like regular globals. Also, this PR update two now deprecated API usage of `getFirstNonPHI`
1 parent 1fd657e commit 55416ca

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,8 @@ void AddressSanitizer::instrumentSyclStaticLocalMemory(
18301830
// Instument dynamic local memory
18311831
bool AddressSanitizer::instrumentSyclDynamicLocalMemory(
18321832
Function &F, ArrayRef<Instruction *> RetVec) {
1833-
InstrumentationIRBuilder IRB(F.getEntryBlock().getFirstNonPHI());
1833+
InstrumentationIRBuilder IRB(&F.getEntryBlock(),
1834+
F.getEntryBlock().getFirstNonPHIIt());
18341835

18351836
SmallVector<Argument *> LocalArgs;
18361837
for (auto &Arg : F.args()) {
@@ -1868,7 +1869,8 @@ bool AddressSanitizer::instrumentSyclDynamicLocalMemory(
18681869
// "__asan_launch" if it's an extended kernel, and store 0 if not
18691870
void AddressSanitizer::instrumentInitAsanLaunchInfo(
18701871
Function &F, const TargetLibraryInfo *TLI) {
1871-
InstrumentationIRBuilder IRB(F.getEntryBlock().getFirstNonPHI());
1872+
InstrumentationIRBuilder IRB(&F.getEntryBlock(),
1873+
F.getEntryBlock().getFirstNonPHIIt());
18721874
if (F.arg_size()) {
18731875
auto *LastArg = F.getArg(F.arg_size() - 1);
18741876
if (LastArg->getName() == "__asan_launch") {
@@ -2891,6 +2893,11 @@ void ModuleAddressSanitizer::instrumentDeviceGlobal(IRBuilder<> &IRB) {
28912893
StructType *StructTy = StructType::get(IntptrTy, IntptrTy, IntptrTy);
28922894

28932895
for (auto &G : M.globals()) {
2896+
// DeviceSanitizers cannot handle nameless globals, therefore we set a name
2897+
// for them so that we can handle them like regular globals.
2898+
if (G.getName().empty() && G.hasInternalLinkage())
2899+
G.setName("nameless_global");
2900+
28942901
if (isUnsupportedDeviceGlobal(&G))
28952902
continue;
28962903

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,11 @@ void MemorySanitizerOnSpirv::instrumentGlobalVariables() {
939939
StructType *StructTy = StructType::get(IntptrTy, IntptrTy);
940940

941941
for (auto &G : M.globals()) {
942+
// DeviceSanitizers cannot handle nameless globals, therefore we set a name
943+
// for them so that we can handle them like regular globals.
944+
if (G.getName().empty() && G.hasInternalLinkage())
945+
G.setName("nameless_global");
946+
942947
if (isUnsupportedDeviceGlobal(&G)) {
943948
for (auto *User : G.users())
944949
if (auto *Inst = dyn_cast<Instruction>(User))

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:
66
target triple = "spir64-unknown-unknown"
77

88
@dev_global = addrspace(1) global { [4 x i32] } zeroinitializer #0
9+
@0 = internal addrspace(1) global i32 0, align 4 ;nameless global
10+
@1 = internal addrspace(1) global i32 0, align 4 ;nameless global
911

1012
; CHECK: @dev_global = addrspace(1) global { { [4 x i32] }, [16 x i8] }
13+
; CHECK: @nameless_global
14+
; CHECK: @nameless_global.1
1115
; CHECK: @__AsanDeviceGlobalMetadata = appending local_unnamed_addr addrspace(1) global [1 x { i64, i64, i64 }] [{ i64, i64, i64 } { i64 16, i64 32, i64 ptrtoint (ptr addrspace(1) @dev_global to i64) }]
1216

1317
attributes #0 = { "sycl-device-global-size"="16" "sycl-device-image-scope" }

llvm/test/Instrumentation/MemorySanitizer/SPIRV/instrument_device_global.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ target triple = "spir64-unknown-unknown"
55
@.str = external addrspace(1) constant [59 x i8]
66
@__spirv_BuiltInGlobalInvocationId = external addrspace(1) constant <3 x i64>
77
@dev_global_no_users = dso_local addrspace(1) global { [4 x i32] } zeroinitializer
8+
@0 = internal global i32 0, align 4 ;nameless global
9+
@1 = internal global i32 0, align 4 ;nameless global
810

911
define spir_func void @_ZZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_ENKUlvE_clEv() {
1012
entry:
1113
%call = call spir_func ptr addrspace(4) null(ptr addrspace(4) addrspacecast (ptr addrspace(1) @.str to ptr addrspace(4)), i64 0)
1214
ret void
1315
}
1416

17+
; CHECK: @nameless_global
18+
; CHECK: @nameless_global.1
1519
; CHECK: @__MsanDeviceGlobalMetadata
1620
; CHECK-NOT: @__spirv_BuiltInGlobalInvocationId
1721
; CHECK-NOT: @dev_global_no_users

0 commit comments

Comments
 (0)