Skip to content

Commit

Permalink
Fix crash on recursive types. (shader-slang#5796)
Browse files Browse the repository at this point in the history
Co-authored-by: Ellie Hermaszewska <[email protected]>
  • Loading branch information
csyonghe and expipiplus1 authored Dec 9, 2024
1 parent 2e7774a commit 2bec21e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 6 additions & 4 deletions source/slang/slang-lower-to-ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11384,6 +11384,12 @@ RefPtr<IRModule> generateIRForTranslationUnit(

if (compileRequest->getLinkage()->m_optionSet.shouldRunNonEssentialValidation())
{
// We don't allow recursive types.
checkForRecursiveTypes(module, compileRequest->getSink());

if (compileRequest->getSink()->getErrorCount() != 0)
return module;

// Propagate `constexpr`-ness through the dataflow graph (and the
// call graph) based on constraints imposed by different instructions.
propagateConstExpr(module, compileRequest->getSink());
Expand All @@ -11395,10 +11401,6 @@ RefPtr<IRModule> generateIRForTranslationUnit(
// instructions remain.

checkForMissingReturns(module, compileRequest->getSink());

// We don't allow recursive types.
checkForRecursiveTypes(module, compileRequest->getSink());

// Check for invalid differentiable function body.
checkAutoDiffUsages(module, compileRequest->getSink());

Expand Down
14 changes: 14 additions & 0 deletions tests/diagnostics/recursive-type.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):-target spirv

// CHECK: error 41001:

struct Outer {
Outer next; // non-pointer
int y;
};
RWStructuredBuffer<Outer> Buf;

[numthreads(1,1,1)]
void csmain() {
Buf[0].y = 0;
}

0 comments on commit 2bec21e

Please sign in to comment.