From afb1405bf7974d714cee10fcce0c61fe28cd075d Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 27 Sep 2024 17:11:07 -0700 Subject: Fix l-value computation for subscript call. (#5177) --- tests/bugs/gh-4971-2.slang | 23 +++++++++++++++++++++++ tests/bugs/gh-4971.slang | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/bugs/gh-4971-2.slang create mode 100644 tests/bugs/gh-4971.slang (limited to 'tests/bugs') diff --git a/tests/bugs/gh-4971-2.slang b/tests/bugs/gh-4971-2.slang new file mode 100644 index 000000000..78efded79 --- /dev/null +++ b/tests/bugs/gh-4971-2.slang @@ -0,0 +1,23 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +struct Test { + RWStructuredBuffer val; + __subscript(int x, int y)->int + { + get { return val[x * 3 + y]; } + set { val[x * 3 + y] = newValue; } + } +} +Test test; + +[numthreads(1, 1, 1)] +void computeMain() +{ + // test[0,0] is not an l-value because `test` is a read-only parameter, + // and the `set` accessor is by-default `mutating`, which means that it is + // only callable when `test` itself is l-value. + + // CHECK: ([[# @LINE+1]]): error 30011 + test[0,0] = 1; + +} \ No newline at end of file diff --git a/tests/bugs/gh-4971.slang b/tests/bugs/gh-4971.slang new file mode 100644 index 000000000..948e43385 --- /dev/null +++ b/tests/bugs/gh-4971.slang @@ -0,0 +1,25 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-d3d11 -output-using-type + +struct Test { + RWStructuredBuffer val; + __subscript(int x, int y)->int + { + get { return val[x * 3 + y]; } + [nonmutating] set { val[x * 3 + y] = newValue; } + } +} +Test test; + +//TEST_INPUT: set test = {out ubuffer(data=[0 0 0 0 0 0 0 0 0], stride=4)}; + +[numthreads(1, 1, 1)] +void computeMain() +{ + // test[0,0] should be a valid l-value here because although `test` is + // a read-only parameter, the `set` accessor is marked as `nonmutating`, + // which means that it can be called even when `test` is not mutable. + + // CHECK: 1 + test[0,0] = 1; +} \ No newline at end of file -- cgit v1.2.3