Skip to content

Commit 2ba2662

Browse files
committed
wip
1 parent 48716c0 commit 2ba2662

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

llvm/lib/SYCLLowerIR/SanitizeDeviceGlobal.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ static bool instrumentDeviceGlobal(Module &M) {
5050
if (!isDeviceGlobalVariable(G) || !hasDeviceImageScopeProperty(G))
5151
continue;
5252

53+
if (G.getName().starts_with("__Asan"))
54+
continue;
55+
5356
Type *Ty = G.getValueType();
5457
const uint64_t SizeInBytes = DL.getTypeAllocSize(Ty);
5558
const uint64_t RightRedzoneSize = [&] {

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "llvm/IR/Intrinsics.h"
6060
#include "llvm/IR/LLVMContext.h"
6161
#include "llvm/IR/MDBuilder.h"
62+
#include "llvm/IR/Mangler.h"
6263
#include "llvm/IR/Metadata.h"
6364
#include "llvm/IR/Module.h"
6465
#include "llvm/IR/Type.h"
@@ -1327,13 +1328,25 @@ static GlobalVariable *GetOrCreateGlobalString(Module &M, StringRef Name,
13271328
return StringGV;
13281329
}
13291330

1331+
static std::string SYCLUniqueStableId(const GlobalValue *GV,
1332+
const DataLayout &DL) {
1333+
std::string Buffer;
1334+
llvm::raw_string_ostream Out(Buffer);
1335+
1336+
Mangler Mgl;
1337+
Mgl.getNameWithPrefix(Out, GV, true);
1338+
1339+
return Out.str();
1340+
}
1341+
13301342
// Append a new argument "launch_data" to user's spir_kernels
13311343
static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM) {
13321344
SmallVector<Function *> SpirFixupKernels;
13331345
SmallVector<Constant *, 8> SpirKernelsMetadata;
13341346
CallGraph CG(M);
13351347

1336-
Type *IntptrTy = M.getDataLayout().getIntPtrType(M.getContext());
1348+
auto DL = M.getDataLayout();
1349+
Type *IntptrTy = DL.getIntPtrType(M.getContext());
13371350

13381351
// SpirKernelsMetadata only saves fixed kernels, and is described by
13391352
// following structure:
@@ -1379,6 +1392,13 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM) {
13791392
MetadataInitializer, "__AsanKernelMetadata", nullptr,
13801393
GlobalValue::NotThreadLocal, 1);
13811394
AsanSpirKernelMetadata->setUnnamedAddr(GlobalValue::UnnamedAddr::Local);
1395+
// Add device global attributes
1396+
AsanSpirKernelMetadata->addAttribute(
1397+
"sycl-device-global-size", std::to_string(DL.getTypeAllocSize(ArrayTy)));
1398+
AsanSpirKernelMetadata->addAttribute("sycl-device-image-scope");
1399+
AsanSpirKernelMetadata->addAttribute("sycl-host-access", "2");
1400+
AsanSpirKernelMetadata->addAttribute("sycl-unique-id",
1401+
"_Z20__AsanKernelMetadata");
13821402

13831403
// Handle SpirFixupKernels
13841404
SmallVector<std::pair<Function *, Function *>> SpirFuncs;

0 commit comments

Comments
 (0)