From 3b0de8b6ea484091146f61e663c63beeac5b4798 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 15 May 2024 18:07:36 -0700 Subject: 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. --- tests/bugs/gh-4150.slang | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/bugs/gh-4150.slang (limited to 'tests/bugs') 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 +{ +#ifdef ERROR2 + // expect error: cannot define static member with unsized type. + // CHECK2:([[# @LINE+1]]): error 30071 + static [[vk::binding(0, 0)]] vector rwtable[]; +#else + static [[vk::binding(0, 0)]] vector rwtable[4]; +#endif + static vector get(uint image_index) { return rwtable[image_index]; } +} + +struct Push +{ + uint image_id; +}; +[[vk::push_constant]] Push p; +RWStructuredBuffer 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::get(p.image_id); +#else + RWTex::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. +} -- cgit v1.2.3