diff options
| author | Yong He <yonghe@outlook.com> | 2024-05-15 18:07:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-15 18:07:36 -0700 |
| commit | 3b0de8b6ea484091146f61e663c63beeac5b4798 (patch) | |
| tree | 8093bc0af8d0801435c29abf5c5f1fdd3e7cc09a /tests | |
| parent | cc88530a722cc2ce7a09f2a39dadeeb504e2f221 (diff) | |
Add diagnostic to prevent defining unsized variables. (#4168)
* Add diagnostic to prevent defining unsized static variables.
* Fix tests.
* Add more tests.
* Fix to allow defining variables of link-time size.
* update diagnostic message.
* Fix tests.
* Simplify code.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/bugs/gh-4150.slang | 49 | ||||
| -rw-r--r-- | tests/diagnostics/unsized.slang | 1 |
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/bugs/gh-4150.slang b/tests/bugs/gh-4150.slang new file mode 100644 index 000000000..031d778a9 --- /dev/null +++ b/tests/bugs/gh-4150.slang @@ -0,0 +1,49 @@ +//TEST:SIMPLE(filecheck=CHECK1):-target spirv -DERROR1 +//TEST:SIMPLE(filecheck=CHECK2):-target spirv -DERROR2 +extern static const int constValue = 1; + +struct RWTex<T : __BuiltinRealType, let N : uint> +{ +#ifdef ERROR2 + // expect error: cannot define static member with unsized type. + // CHECK2:([[# @LINE+1]]): error 30071 + static [[vk::binding(0, 0)]] vector<T,N> rwtable[]; +#else + static [[vk::binding(0, 0)]] vector<T,N> rwtable[4]; +#endif + static vector<T, N> get(uint image_index) { return rwtable[image_index]; } +} + +struct Push +{ + uint image_id; +}; +[[vk::push_constant]] Push p; +RWStructuredBuffer<float3> output; +[shader("compute")] +[numthreads(8, 8, 1)] +void main(uint3 pixel_i : SV_DispatchThreadID) +{ + output[0] = +#ifdef ERROR1 + // expect error: trying to specialize RWTex, which has two arguments, with only one argument. + // CHECK1:([[# @LINE+1]]): error 30075 + RWTex<float3>::get(p.image_id); +#else + RWTex<float, 3>::get(p.image_id); +#endif + //CHECK1:([[# @LINE+1]]): error 30071 + static float sa1[]; + + //CHECK1:([[# @LINE+1]]): error 30071 + float sa2[]; + + //CHECK1-NOT:([[# @LINE+1]]): error + static float sa3[] = { 1, 2, 3 }; // should be ok. + + //CHECK1-NOT:([[# @LINE+1]]): error + float sa4[] = { 1, 2, 3 }; // should be ok. + + //CHECK1-NOT:([[# @LINE+1]]): error + float sa5[constValue]; // should be ok. +} diff --git a/tests/diagnostics/unsized.slang b/tests/diagnostics/unsized.slang index 6bcad95a9..6b14353b5 100644 --- a/tests/diagnostics/unsized.slang +++ b/tests/diagnostics/unsized.slang @@ -5,6 +5,7 @@ extern static const int size = 1; struct V { // CHECK-DAG: ([[# @LINE+1]]): error 30070 + int c[]; int b[size]; int a[]; } |
