summaryrefslogtreecommitdiffstats
path: root/tests/language-feature
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2025-05-16 10:44:44 -0700
committerGitHub <noreply@github.com>2025-05-16 10:44:44 -0700
commit0651ffb6489282f0f902ec5f630821a7b9d848bb (patch)
tree28b27f1b5cc19520b4c54c046a260710d3e7fdd6 /tests/language-feature
parent8683b85c0494db99feb08b6efcdc26dfe006729f (diff)
Enforce rule that `export`/`extern` (non cpp) must be `const` (#7113)
* Enforce rule that `export`/`extern` (non cpp) must be `const` fixes: #5570 Problem: 1. we allow non-const-link-time-var to be linked to a const-link-time-var. 2. problem is that: module use site has const var, so, we emit OpStore %Ptr %Const in IR, this is expected, this is good. We fail because we in reality have a OpStore %Ptr %Var (fails since we need a OpLoad in-between) in IR since the module with our link-time-variable-value is a regular variable. 3. We loose the float_litteral talked about inside the github issue since, we technically don't use our variable "VAL" (we never OpLoad from it), so spirv-opt removes the float_litteral, this is a byproduct of the actual issue. Solution: * `export`/`extern` variables must always be `const`. This excludes `__extern_cpp` since `cpp` does not exhibit this issue and works differently. * format code * changel logic and tests to only ensure `static const` with `export`/`extern` * changing the rules: only reqirement is that if we have const we must have static * remove a spirrious change made * fix merge --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests/language-feature')
-rw-r--r--tests/language-feature/constants/link-time-vardecl-must-be-static-const-or-neither.slang32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/language-feature/constants/link-time-vardecl-must-be-static-const-or-neither.slang b/tests/language-feature/constants/link-time-vardecl-must-be-static-const-or-neither.slang
new file mode 100644
index 000000000..a1ae810e1
--- /dev/null
+++ b/tests/language-feature/constants/link-time-vardecl-must-be-static-const-or-neither.slang
@@ -0,0 +1,32 @@
+//TEST:SIMPLE(filecheck=CHECK_PASS): -target spirv -entry computeMain -stage compute -DUSE_EXTERN
+//TEST:SIMPLE(filecheck=CHECK_PASS): -target spirv -entry computeMain -stage compute
+//TEST:SIMPLE(filecheck=CHECK_PASS): -target spirv -entry computeMain -stage compute -DUSE_EXTERN -DUSE_CONST -DUSE_STATIC
+//TEST:SIMPLE(filecheck=CHECK_PASS): -target spirv -entry computeMain -stage compute -DUSE_CONST -DUSE_STATIC
+//CHECK_PASS-NOT: error 31223
+
+//TEST:SIMPLE(filecheck=CHECK_FAIL): -target spirv -entry computeMain -stage compute -DUSE_EXTERN -DUSE_CONST
+//TEST:SIMPLE(filecheck=CHECK_FAIL): -target spirv -entry computeMain -stage compute -DUSE_CONST
+//TEST:SIMPLE(filecheck=CHECK_FAIL): -target spirv -entry computeMain -stage compute -DUSE_EXTERN -DUSE_STATIC
+//TEST:SIMPLE(filecheck=CHECK_FAIL): -target spirv -entry computeMain -stage compute -DUSE_STATIC
+//CHECK_FAIL: error 31223
+
+
+#ifdef USE_CONST
+const
+#endif
+#ifdef USE_STATIC
+static
+#endif
+#ifdef USE_EXTERN
+extern int num;
+#else
+export int num = 10;
+#endif
+
+RWStructuredBuffer<float> outputBuffer;
+
+[numthreads(1,1,1)]
+void computeMain()
+{
+ outputBuffer[0] = num;
+}