Skip to content

Commit 5546e64

Browse files
committed
[DeviceSanitizer] Generate unique sycl-unique-id for device global.
1 parent bf20e6e commit 5546e64

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/Analysis/TargetLibraryInfo.h"
3232
#include "llvm/Analysis/ValueTracking.h"
3333
#include "llvm/BinaryFormat/MachO.h"
34+
#include "llvm/Bitcode/BitcodeWriter.h"
3435
#include "llvm/Demangle/Demangle.h"
3536
#include "llvm/IR/Argument.h"
3637
#include "llvm/IR/Attributes.h"
@@ -68,6 +69,7 @@
6869
#include "llvm/Support/CommandLine.h"
6970
#include "llvm/Support/Debug.h"
7071
#include "llvm/Support/ErrorHandling.h"
72+
#include "llvm/Support/MD5.h"
7173
#include "llvm/Support/MathExtras.h"
7274
#include "llvm/Support/Path.h"
7375
#include "llvm/Support/raw_ostream.h"
@@ -1379,8 +1381,15 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM,
13791381
"sycl-device-global-size", std::to_string(DL.getTypeAllocSize(ArrayTy)));
13801382
AsanSpirKernelMetadata->addAttribute("sycl-device-image-scope");
13811383
AsanSpirKernelMetadata->addAttribute("sycl-host-access", "0"); // read only
1384+
// Create a memory buffer to hold the serialized module
1385+
std::string Buffer;
1386+
llvm::raw_string_ostream Stream(Buffer);
1387+
llvm::WriteBitcodeToFile(M, Stream);
1388+
Stream.flush();
1389+
auto ModuleHash = llvm::utohexstr(MD5Hash(Buffer), true);
1390+
13821391
AsanSpirKernelMetadata->addAttribute("sycl-unique-id",
1383-
"_Z20__AsanKernelMetadata");
1392+
"_Z20__AsanKernelMetadata" + ModuleHash);
13841393
AsanSpirKernelMetadata->setDSOLocal(true);
13851394

13861395
// Handle SpirFixupKernels

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ entry:
2525
attributes #0 = { sanitize_address }
2626
;; sycl-device-global-size = 16 * 2
2727
;; sycl-host-access = 0 read-only
28-
; CHECK: attributes #{{.*}} = { "sycl-device-global-size"="32" "sycl-device-image-scope" "sycl-host-access"="0" "sycl-unique-id"="_Z20__AsanKernelMetadata" }
28+
; CHECK: attributes #{{.*}} = { "sycl-device-global-size"="32" "sycl-device-image-scope" "sycl-host-access"="0" "sycl-unique-id"="_Z20__AsanKernelMetadata{{.*}}" }

0 commit comments

Comments
 (0)