Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,8 @@ void AddressSanitizer::instrumentSyclStaticLocalMemory(
// Instument dynamic local memory
bool AddressSanitizer::instrumentSyclDynamicLocalMemory(
Function &F, ArrayRef<Instruction *> RetVec) {
InstrumentationIRBuilder IRB(F.getEntryBlock().getFirstNonPHI());
InstrumentationIRBuilder IRB(&F.getEntryBlock(),
F.getEntryBlock().getFirstNonPHIIt());

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

for (auto &G : M.globals()) {
// DeviceSanitizers cannot handle nameless globals, therefore we set a name
// for them so that we can handle them like regular globals.
if (G.getName().empty() && G.hasInternalLinkage())
G.setName("nameless_global");

if (isUnsupportedDeviceGlobal(&G))
continue;

Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,11 @@ void MemorySanitizerOnSpirv::instrumentGlobalVariables() {
StructType *StructTy = StructType::get(IntptrTy, IntptrTy);

for (auto &G : M.globals()) {
// DeviceSanitizers cannot handle nameless globals, therefore we set a name
// for them so that we can handle them like regular globals.
if (G.getName().empty() && G.hasInternalLinkage())
G.setName("nameless_global");

if (isUnsupportedDeviceGlobal(&G)) {
for (auto *User : G.users())
if (auto *Inst = dyn_cast<Instruction>(User))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:
target triple = "spir64-unknown-unknown"

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

; CHECK: @dev_global = addrspace(1) global { { [4 x i32] }, [16 x i8] }
; CHECK: @nameless_global
; CHECK: @nameless_global.1
; 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) }]

attributes #0 = { "sycl-device-global-size"="16" "sycl-device-image-scope" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ target triple = "spir64-unknown-unknown"
@.str = external addrspace(1) constant [59 x i8]
@__spirv_BuiltInGlobalInvocationId = external addrspace(1) constant <3 x i64>
@dev_global_no_users = dso_local addrspace(1) global { [4 x i32] } zeroinitializer
@0 = internal global i32 0, align 4 ;nameless global
@1 = internal global i32 0, align 4 ;nameless global

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

; CHECK: @nameless_global
; CHECK: @nameless_global.1
; CHECK: @__MsanDeviceGlobalMetadata
; CHECK-NOT: @__spirv_BuiltInGlobalInvocationId
; CHECK-NOT: @dev_global_no_users
Expand Down