Skip to content

Commit 49b57df

Browse files
authored
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.
1 parent 80fcab8 commit 49b57df

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ void DXILBitcodeWriter::writeValueAsMetadata(
13451345
Ty = TypedPointerType::get(F->getFunctionType(), F->getAddressSpace());
13461346
else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
13471347
Ty = TypedPointerType::get(GV->getValueType(), GV->getAddressSpace());
1348-
Record.push_back(getTypeID(Ty));
1348+
Record.push_back(getTypeID(Ty, V));
13491349
Record.push_back(VE.getValueID(V));
13501350
Stream.EmitRecord(bitc::METADATA_VALUE, Record, 0);
13511351
Record.clear();

llvm/test/tools/dxil-dis/metadata.ll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
; RUN: llc --filetype=obj %s -o - | dxil-dis
1+
; RUN: llc --filetype=obj %s -o - | dxil-dis
22
target triple = "dxil-unknown-shadermodel6.7-library"
33

4+
define void @kernel(ptr addrspace(1)) {
5+
ret void
6+
}
7+
48
!llvm.foo = !{!0}
59
!llvm.bar = !{!1}
10+
!llvm.baz = !{!2}
611

712
!0 = !{i32 42}
813
!1 = !{!"Some MDString"}
14+
!2 = !{ptr @kernel}
915

1016
; CHECK: !llvm.foo = !{!0}
1117
; CHECK: !llvm.bar = !{!1}
18+
; CHECK: !llvm.baz = !{!2}
1219
; CHECK: !0 = !{i32 42}
1320
; CHECK: !1 = !{!"Some MDString"}
21+
; CHECK: !2 = !{void (i8 addrspace(1)*)* @kernel}

llvm/tools/dxil-dis/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ include(ExternalProject)
2525

2626
set(SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/DXC-src)
2727
set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/DXC-bins)
28-
set(GIT_SETTINGS GIT_REPOSITORY https://github.com/microsoft/DirectXShaderCompiler.git)
28+
set(GIT_SETTINGS
29+
GIT_REPOSITORY https://github.com/microsoft/DirectXShaderCompiler.git
30+
GIT_TAG main)
2931

3032
if (DXC_SOURCE_DIR)
3133
set(SOURCE_DIR ${DXC_SOURCE_DIR})

0 commit comments

Comments
 (0)