summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2025-07-30 14:23:27 -0700
committerGitHub <noreply@github.com>2025-07-30 21:23:27 +0000
commitc4dd2eb0033b3eaf683791a6666cff63aeb9f139 (patch)
tree685ee2df21730638ed56d00723af08b92bf8915c /tests
parent5f9547b9c8ebf3458516d170dcc7b9a5f31a3263 (diff)
disallow `static const` variables without default-value (#7993)
* Fix static const variables without initializers causing internal errors Add validation in SemanticsDeclHeaderVisitor::checkVarDeclCommon to detect static const variables without initializers and emit proper error diagnostics instead of allowing internal errors to escape during SPIR-V generation. - Add new diagnostic (ID 31225) for static const variables without initializers - Skip validation for extern static const variables - Skip validation for interface member variables - Add comprehensive test case covering various scenarios Fixes #7989 Co-authored-by: ArielG-NV <ArielG-NV@users.noreply.github.com> * clean up test and implementation * format code (#7994) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: ArielG-NV <ArielG-NV@users.noreply.github.com> Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/bugs/static-const-without-default-value.slang27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/bugs/static-const-without-default-value.slang b/tests/bugs/static-const-without-default-value.slang
new file mode 100644
index 000000000..b9d9055c9
--- /dev/null
+++ b/tests/bugs/static-const-without-default-value.slang
@@ -0,0 +1,27 @@
+// TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry computeMain -emit-spirv-directly
+
+// Test cases for static const variables without initializers producing an error
+
+// CHECK: ([[# @LINE+1]]): error 31225
+static const int globalVar;
+
+// CHECK-NOT: error 31225
+
+// This should NOT cause an error - extern static const
+extern static const int externVar;
+
+interface ITest
+{
+ // This should NOT cause an error - interface member
+ static const int interfaceVar;
+}
+
+// This should NOT cause an error - has initializer
+static const int initializedVar = 42;
+const int nonStaticVar;
+static int nonConstVar;
+
+[numthreads(1,1,1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+}