From 6c8540ee8166ce84577ad4a05660e3678ded8906 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 6 Dec 2024 19:32:30 -0800 Subject: [PATCH] Fix crash on recursive types. --- 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