Skip to content

[HIP] disable sanitizer for __hip_cuid #141581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged

Conversation

yxsamliu
Copy link
Collaborator

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

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

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR disables sanitization for the __hip_cuid globals since they are used only for identification. Key changes include adding a new test case to verify that the __hip_cuid global variable is not sanitized and updating CodeGenModule to disable sanitizer processing for this global.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
clang/test/CodeGenCUDA/nosanitize-cuid.hip Added a test to verify that __hip_cuid globals are excluded from sanitization.
clang/lib/CodeGen/CodeGenModule.cpp Updated the module to disable sanitization for __hip_cuid globals.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels May 27, 2025
@llvmbot
Copy link
Member

llvmbot commented May 27, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Yaxun (Sam) Liu (yxsamliu)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/141581.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1)
  • (added) clang/test/CodeGenCUDA/nosanitize-cuid.hip (+6)
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

@yxsamliu yxsamliu merged commit c720f92 into llvm:main May 27, 2025
14 checks passed
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
Global variable `__hip_cuid_*` is for identifying purpose and does not
need sanitization, therefore disable it for sanitizers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants