Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/clang/lib/CodeGen/CGStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) {

// HLSL Change Begins.
void CodeGenFunction::EmitDiscardStmt(const DiscardStmt &S) {
// Skip unreachable discard.
if (!HaveInsertPoint())
return;

CGM.getHLSLRuntime().EmitHLSLDiscard(*this);
}
// HLSL Change Ends.
Expand Down
21 changes: 21 additions & 0 deletions tools/clang/test/DXC/FinishCodeGen/unreachable-discard.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %dxc /T ps_6_5 -fcgl %s | FileCheck %s

// Compiling this HLSL would trigger an assertion:
// While deleting: void (i32, float)* %dx.hl.op..void (i32, float)
// Use still stuck around after Def is destroyed: call void @"dx.hl.op..void (i32, float)"(i32 120, float -1.000000e+00), !dbg <0x503000001cc8>
// Error: assert(use_empty() && "Uses remain when a value is destroyed!")
// File: <snip>/src/external/DirectXShaderCompiler/lib/IR/Value.cpp(83)
//
// Bug was fixed in CodeGenFunction::EmitDiscardStmt by skipping the emission of
// an unreachable discard.

// CHECK: define void @main()
// CHECK: br label %
// CHECK-NOT: call void @"dx.hl.op..void (i32, float)"
// CHECK: ret void

void main() {
while (true) {
}
discard;
}