Skip to content

Commit b793c33

Browse files
authored
[spirv] support non-existing header file include (#3167)
1 parent 9459577 commit b793c33

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

tools/clang/lib/SPIRV/EmitVisitor.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,21 @@ bool EmitVisitor::visit(SpirvSource *inst) {
521521
}
522522
}
523523

524-
// Note: in order to improve performance and avoid multiple copies, we
525-
// encode this (potentially large) string directly into the debugFileBinary.
526-
const auto &words = string::encodeSPIRVString(firstSnippet.getValue());
527-
const auto numWordsInInstr = curInst.size() + words.size();
528-
curInst[0] |= static_cast<uint32_t>(numWordsInInstr) << 16;
529-
debugFileBinary.insert(debugFileBinary.end(), curInst.begin(),
530-
curInst.end());
531-
debugFileBinary.insert(debugFileBinary.end(), words.begin(), words.end());
524+
if (firstSnippet.hasValue()) {
525+
// Note: in order to improve performance and avoid multiple copies, we
526+
// encode this (potentially large) string directly into the
527+
// debugFileBinary.
528+
const auto &words = string::encodeSPIRVString(firstSnippet.getValue());
529+
const auto numWordsInInstr = curInst.size() + words.size();
530+
curInst[0] |= static_cast<uint32_t>(numWordsInInstr) << 16;
531+
debugFileBinary.insert(debugFileBinary.end(), curInst.begin(),
532+
curInst.end());
533+
debugFileBinary.insert(debugFileBinary.end(), words.begin(), words.end());
534+
} else {
535+
curInst[0] |= static_cast<uint32_t>(curInst.size()) << 16;
536+
debugFileBinary.insert(debugFileBinary.end(), curInst.begin(),
537+
curInst.end());
538+
}
532539
} else {
533540
curInst[0] |= static_cast<uint32_t>(curInst.size()) << 16;
534541
debugFileBinary.insert(debugFileBinary.end(), curInst.begin(),
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Run: %dxc -T ps_6_0 -E main -Zi
2+
3+
// CHECK: OpString "non_existing_file.txt"
4+
5+
#line 1 "non_existing_file.txt"
6+
7+
struct PSInput
8+
{
9+
float4 color : COLOR;
10+
};
11+
12+
float4 main(PSInput input) : SV_TARGET
13+
{
14+
return input.color;
15+
}

tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,9 @@ TEST_F(FileTest, SpirvLegalizationTextureBuffer) {
15591559
TEST_F(FileTest, SpirvDebugOpSource) {
15601560
runFileTest("spirv.debug.opsource.hlsl");
15611561
}
1562+
TEST_F(FileTest, SpirvDebugOpSourceNonExistingFile) {
1563+
runFileTest("spirv.debug.source.non.existing.file.hlsl");
1564+
}
15621565

15631566
TEST_F(FileTest, SpirvDebugOpLine) { runFileTest("spirv.debug.opline.hlsl"); }
15641567
TEST_F(FileTest, SpirvDebugOpLineBranch) {

0 commit comments

Comments
 (0)