https://github.com/mtrofin updated 
https://github.com/llvm/llvm-project/pull/209239

>From e4bdd347ceaf772187ac185cda7e5cfcc5ed503c Mon Sep 17 00:00:00 2001
From: Mircea Trofin <[email protected]>
Date: Mon, 13 Jul 2026 09:36:25 -0700
Subject: [PATCH] [clang][cuda] Use the source filename for module ID

---
 clang/lib/CodeGen/CGCUDANV.cpp        |  3 +--
 clang/test/CodeGenCUDA/device-stub.cu | 13 +++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 733f2b7ecb46e..521e6c43f678f 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1045,8 +1045,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() 
{
     llvm::raw_svector_ostream OS(ModuleID);
     OS << ModuleIDPrefix
        << llvm::format("%" PRIx64,
-                       llvm::GlobalValue::getGUIDAssumingExternalLinkage(
-                           FatbinWrapper->getName()));
+                       llvm::MD5Hash(TheModule.getSourceFileName()));
     llvm::Constant *ModuleIDConstant = makeConstantArray(
         std::string(ModuleID), "", ModuleIDSectionName, 32, /*AddNull=*/true);
 
diff --git a/clang/test/CodeGenCUDA/device-stub.cu 
b/clang/test/CodeGenCUDA/device-stub.cu
index 38c7dc711ef1d..307ab190aa5be 100644
--- a/clang/test/CodeGenCUDA/device-stub.cu
+++ b/clang/test/CodeGenCUDA/device-stub.cu
@@ -64,6 +64,19 @@
 // RUN:     -o - -x hip\
 // RUN:   | FileCheck -allow-deprecated-dag-overlap %s 
--check-prefixes=ALL,WIN,HIP,HIPNEF
 
+// Verify that module IDs are distinct when the module source path is distinct.
+// RUN: rm -rf %t_distinct
+// RUN: mkdir -p %t_distinct
+// RUN: cp %s %t_distinct/filename1.cu
+// RUN: cp %s %t_distinct/filename2.cu
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm 
%t_distinct/filename1.cu -I%S \
+// RUN:     -target-sdk-version=8.0 -fgpu-rdc -fcuda-include-gpubinary %t \
+// RUN:     -o - | grep __nv_module_id &> %t_module_id_1
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm 
%t_distinct/filename2.cu -I%S \
+// RUN:     -target-sdk-version=8.0 -fgpu-rdc -fcuda-include-gpubinary %t \
+// RUN:     -o - | grep __nv_module_id &> %t_module_id_2
+// RUN: not diff %t_module_id_1 %t_module_id_2
+
 #include "Inputs/cuda.h"
 
 #ifndef NOGLOBALS

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to