https://github.com/yxsamliu created 
https://github.com/llvm/llvm-project/pull/141581

Global variable `__hip_cuid_*` is for identifying purpose and does not need 
sanitization, therefore disable it for sanitizers.

>From 503ee3dd5144b4cc2dd83488b2194900605217fd Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" <yaxun....@amd.com>
Date: Tue, 27 May 2025 00:38:24 -0400
Subject: [PATCH] [HIP] disable sanitizer for __hip_cuid

Global variable __hip_cuid_* is for identifying purpose
and does not need sanitization, therefore disable it
for sanitizers.
---
 clang/lib/CodeGen/CodeGenModule.cpp        | 1 +
 clang/test/CodeGenCUDA/nosanitize-cuid.hip | 6 ++++++
 2 files changed, 7 insertions(+)
 create mode 100644 clang/test/CodeGenCUDA/nosanitize-cuid.hip

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 16e010adbeb5f..039507bc03510 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -971,6 +971,7 @@ void CodeGenModule::Release() {
         getModule(), Int8Ty, false, llvm::GlobalValue::ExternalLinkage,
         llvm::Constant::getNullValue(Int8Ty),
         "__hip_cuid_" + getContext().getCUIDHash());
+    getSanitizerMetadata()->disableSanitizerForGlobal(GV);
     addCompilerUsedGlobal(GV);
   }
   emitLLVMUsed();
diff --git a/clang/test/CodeGenCUDA/nosanitize-cuid.hip 
b/clang/test/CodeGenCUDA/nosanitize-cuid.hip
new file mode 100644
index 0000000000000..4af83c91ac883
--- /dev/null
+++ b/clang/test/CodeGenCUDA/nosanitize-cuid.hip
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fsanitize=address 
-fcuda-is-device \
+// RUN:    -emit-llvm -cuid=abcd -o - %s | FileCheck  %s
+
+#include "Inputs/cuda.h"
+
+// CHECK: @__hip_cuid_{{.*}} = {{.*}} no_sanitize_address

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to