From 2bec21e91164c8533e93540dc8b610fb24205b7e Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 9 Dec 2024 04:46:09 -0800 Subject: [PATCH] Fix crash on recursive types. (#5796) Co-authored-by: Ellie Hermaszewska --- source/slang/slang-lower-to-ir.cpp | 10 ++++++---- tests/diagnostics/recursive-type.slang | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 tests/diagnostics/recursive-type.slang diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 06c5f005b5..75cf421af0 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -11384,6 +11384,12 @@ RefPtr 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()); @@ -11395,10 +11401,6 @@ RefPtr 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()); diff --git a/tests/diagnostics/recursive-type.slang b/tests/diagnostics/recursive-type.slang new file mode 100644 index 0000000000..90f49aa86d --- /dev/null +++ b/tests/diagnostics/recursive-type.slang @@ -0,0 +1,14 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):-target spirv + +// CHECK: error 41001: + +struct Outer { + Outer next; // non-pointer + int y; +}; +RWStructuredBuffer Buf; + +[numthreads(1,1,1)] +void csmain() { + Buf[0].y = 0; +} \ No newline at end of file