https://github.com/AlexVlx updated https://github.com/llvm/llvm-project/pull/116804
>From 02a607446bf23781255f401d880b67c705cf11fd Mon Sep 17 00:00:00 2001 From: Alex Voicu <alexandru.vo...@amd.com> Date: Tue, 19 Nov 2024 13:42:54 +0000 Subject: [PATCH 1/3] Use `used`'s element type if it's available. --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 24a4c2e8303d5a..80e12bef502ace 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -5501,8 +5501,9 @@ void llvm::embedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf, // Save llvm.compiler.used and remove it. SmallVector<Constant *, 2> UsedArray; SmallVector<GlobalValue *, 4> UsedGlobals; - Type *UsedElementType = PointerType::getUnqual(M.getContext()); GlobalVariable *Used = collectUsedGlobalVariables(M, UsedGlobals, true); + Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType() + : PointerType::getUnqual(M.getContext()); for (auto *GV : UsedGlobals) { if (GV->getName() != "llvm.embedded.module" && GV->getName() != "llvm.cmdline") >From 587ca7c62b46edd3c924bcf6e77e490c1125195c Mon Sep 17 00:00:00 2001 From: Alex Voicu <alexandru.vo...@amd.com> Date: Wed, 20 Nov 2024 17:10:37 +0000 Subject: [PATCH 2/3] Add test. --- clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c diff --git a/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c b/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c new file mode 100644 index 00000000000000..5cd0c74a03c200 --- /dev/null +++ b/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -emit-llvm -fcuda-is-device -fembed-bitcode=marker -x hip %s -o - \ +// RUN: | FileCheck %s --check-prefix=CHECK + +// CHECK: @llvm.embedded.module = private addrspace(1) constant [0 x i8] zeroinitializer, section ".llvmbc", align 1 +// CHECK-NEXT: @llvm.cmdline = private addrspace(1) constant [387 x i8] c"{{.*}}", section ".llvmcmd", align 1 +// CHECK-NEXT: @llvm.compiler.used = appending addrspace(1) global [5 x ptr addrspace(4)] [ptr addrspace(4) addrspacecast (ptr addrspace(1) @foo.managed to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @foo to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @__hip_cuid_ to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @llvm.embedded.module to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @llvm.cmdline to ptr addrspace(4))], section "llvm.metadata" + +__attribute__((managed)) int foo = 42; >From ca659d447cfa1f13c41bbf0a2d26b8919b5f185b Mon Sep 17 00:00:00 2001 From: Alex Voicu <alexandru.vo...@amd.com> Date: Wed, 20 Nov 2024 20:02:33 +0000 Subject: [PATCH 3/3] Make test robust. --- clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c b/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c index 5cd0c74a03c200..df7118859c7640 100644 --- a/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c +++ b/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c @@ -2,7 +2,7 @@ // RUN: | FileCheck %s --check-prefix=CHECK // CHECK: @llvm.embedded.module = private addrspace(1) constant [0 x i8] zeroinitializer, section ".llvmbc", align 1 -// CHECK-NEXT: @llvm.cmdline = private addrspace(1) constant [387 x i8] c"{{.*}}", section ".llvmcmd", align 1 +// CHECK-NEXT: @llvm.cmdline = private addrspace(1) constant [{{[0-9]+}} x i8] c"{{.*}}", section ".llvmcmd", align 1 // CHECK-NEXT: @llvm.compiler.used = appending addrspace(1) global [5 x ptr addrspace(4)] [ptr addrspace(4) addrspacecast (ptr addrspace(1) @foo.managed to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @foo to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @__hip_cuid_ to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @llvm.embedded.module to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @llvm.cmdline to ptr addrspace(4))], section "llvm.metadata" __attribute__((managed)) int foo = 42; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits