From c4dd2eb0033b3eaf683791a6666cff63aeb9f139 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Wed, 30 Jul 2025 14:23:27 -0700 Subject: 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 * 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 Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- .../bugs/static-const-without-default-value.slang | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/bugs/static-const-without-default-value.slang (limited to 'tests') 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) +{ +} -- cgit v1.2.3