[llvm] 49b57df - DXIL: Use correct type ID when writing ValueAsMetadata. (#94337)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 11 05:39:01 PDT 2024


Author: Tim Besard
Date: 2024-09-11T14:38:56+02:00
New Revision: 49b57df16144450331b4f90332d6918168b2a306

URL: https://github.com/llvm/llvm-project/commit/49b57df16144450331b4f90332d6918168b2a306
DIFF: https://github.com/llvm/llvm-project/commit/49b57df16144450331b4f90332d6918168b2a306.diff

LOG: DXIL: Use correct type ID when writing ValueAsMetadata. (#94337)

When emitting references to functions as part of `ValueAsMetadata`,
we currently emit the incorrect (typed) pointer, resulting in
crashes during deserialization. Avoid this by correctly mapping the
type during serialization.

Added: 
    

Modified: 
    llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
    llvm/test/tools/dxil-dis/metadata.ll
    llvm/tools/dxil-dis/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
index cd0d6d34e9a67b..45aadac861946b 100644
--- a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
+++ b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
@@ -1345,7 +1345,7 @@ void DXILBitcodeWriter::writeValueAsMetadata(
     Ty = TypedPointerType::get(F->getFunctionType(), F->getAddressSpace());
   else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
     Ty = TypedPointerType::get(GV->getValueType(), GV->getAddressSpace());
-  Record.push_back(getTypeID(Ty));
+  Record.push_back(getTypeID(Ty, V));
   Record.push_back(VE.getValueID(V));
   Stream.EmitRecord(bitc::METADATA_VALUE, Record, 0);
   Record.clear();

diff  --git a/llvm/test/tools/dxil-dis/metadata.ll b/llvm/test/tools/dxil-dis/metadata.ll
index 758860a2deb8f9..18f2530ab8fc27 100644
--- a/llvm/test/tools/dxil-dis/metadata.ll
+++ b/llvm/test/tools/dxil-dis/metadata.ll
@@ -1,13 +1,21 @@
-; RUN: llc --filetype=obj %s -o - | dxil-dis 
+; RUN: llc --filetype=obj %s -o - | dxil-dis
 target triple = "dxil-unknown-shadermodel6.7-library"
 
+define void @kernel(ptr addrspace(1)) {
+    ret void
+}
+
 !llvm.foo = !{!0}
 !llvm.bar = !{!1}
+!llvm.baz = !{!2}
 
 !0 = !{i32 42}
 !1 = !{!"Some MDString"}
+!2 = !{ptr @kernel}
 
 ; CHECK: !llvm.foo = !{!0}
 ; CHECK: !llvm.bar = !{!1}
+; CHECK: !llvm.baz = !{!2}
 ; CHECK: !0 = !{i32 42}
 ; CHECK: !1 = !{!"Some MDString"}
+; CHECK: !2 = !{void (i8 addrspace(1)*)* @kernel}

diff  --git a/llvm/tools/dxil-dis/CMakeLists.txt b/llvm/tools/dxil-dis/CMakeLists.txt
index 9addf108a8614e..d0541fcf802e98 100644
--- a/llvm/tools/dxil-dis/CMakeLists.txt
+++ b/llvm/tools/dxil-dis/CMakeLists.txt
@@ -25,7 +25,9 @@ include(ExternalProject)
 
 set(SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/DXC-src)
 set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/DXC-bins)
-set(GIT_SETTINGS GIT_REPOSITORY https://github.com/microsoft/DirectXShaderCompiler.git)
+set(GIT_SETTINGS
+    GIT_REPOSITORY https://github.com/microsoft/DirectXShaderCompiler.git
+    GIT_TAG main)
 
 if (DXC_SOURCE_DIR)
   set(SOURCE_DIR ${DXC_SOURCE_DIR})


        


More information about the llvm-commits mailing list