From 5d1ba37be64980d80e5106f8664a654d907ebaf4 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Fri, 8 Aug 2025 20:15:25 +0800 Subject: Diagnose on array of parameterblock instead of asserting (#8123) Closes https://github.com/shader-slang/slang/issues/5750 --- source/slang/slang-check-decl.cpp | 18 ++++++++++++++++++ source/slang/slang-check-impl.h | 1 + source/slang/slang-diagnostic-defs.h | 5 +++++ 3 files changed, 24 insertions(+) (limited to 'source') diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index d6bc50b82..72b5c19db 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -2187,6 +2187,10 @@ void SemanticsDeclHeaderVisitor::checkVarDeclCommon(VarDeclBase* varDecl) // arrays in specific cases) // validateArraySizeForVariable(varDecl); + // + // Similarly, we want to check the element type for any restrictions + // + validateArrayElementTypeForVariable(varDecl); } // If there is a matrix layout modifier or texture format modifier, we will modify the type now. @@ -10745,6 +10749,20 @@ void SemanticsVisitor::validateArraySizeForVariable(VarDeclBase* varDecl) } } +void SemanticsVisitor::validateArrayElementTypeForVariable(VarDeclBase* varDecl) +{ + auto arrayType = as(varDecl->type); + if (!arrayType) + return; + + const auto elementType = arrayType->getElementType(); + if (as(elementType)) + { + getSink()->diagnose(varDecl, Diagnostics::disallowedArrayOfParameterBlock); + return; + } +} + bool getExtensionTargetDeclList( ASTBuilder* astBuilder, DeclRefType* targetDeclRefType, diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index 94c595321..d08cae66f 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -2264,6 +2264,7 @@ public: void maybeInferArraySizeForVariable(VarDeclBase* varDecl); void validateArraySizeForVariable(VarDeclBase* varDecl); + void validateArrayElementTypeForVariable(VarDeclBase* varDecl); IntVal* getIntVal(IntegerLiteralExpr* expr); diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index 6f0a6274e..8ec910f15 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -649,6 +649,11 @@ DIAGNOSTIC( cannotConvertArrayOfSmallerToLargerSize, "Cannot convert array of size $0 to array of size $1 as this would truncate data") DIAGNOSTIC(30025, Error, invalidArraySize, "array size must be non-negative.") +DIAGNOSTIC( + 30027, + Error, + disallowedArrayOfParameterBlock, + "Arrays of ParameterBlock are not allowed") DIAGNOSTIC( 30029, Error, -- cgit v1.2.3