summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2025-08-08 20:15:25 +0800
committerGitHub <noreply@github.com>2025-08-08 12:15:25 +0000
commit5d1ba37be64980d80e5106f8664a654d907ebaf4 (patch)
tree039933a1e1a902478b3902f6c350745590ca2a80
parentc7c4816146bb9ec055e9a8f8c3f975624f2fdb07 (diff)
Diagnose on array of parameterblock instead of asserting (#8123)
Closes https://github.com/shader-slang/slang/issues/5750
-rw-r--r--source/slang/slang-check-decl.cpp18
-rw-r--r--source/slang/slang-check-impl.h1
-rw-r--r--source/slang/slang-diagnostic-defs.h5
-rw-r--r--tests/diagnostics/array-parameterblock.slang10
4 files changed, 34 insertions, 0 deletions
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<ArrayExpressionType>(varDecl->type);
+ if (!arrayType)
+ return;
+
+ const auto elementType = arrayType->getElementType();
+ if (as<ParameterBlockType>(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
@@ -650,6 +650,11 @@ DIAGNOSTIC(
"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,
arrayIndexOutOfBounds,
diff --git a/tests/diagnostics/array-parameterblock.slang b/tests/diagnostics/array-parameterblock.slang
new file mode 100644
index 000000000..566694e37
--- /dev/null
+++ b/tests/diagnostics/array-parameterblock.slang
@@ -0,0 +1,10 @@
+//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+}
+
+//CHECK: ([[# @LINE+1]]): error 30027
+uniform ParameterBlock<float> qs[2];
+