diff options
Diffstat (limited to 'tests/bugs')
| -rw-r--r-- | tests/bugs/gh-4971-2.slang | 23 | ||||
| -rw-r--r-- | tests/bugs/gh-4971.slang | 25 |
2 files changed, 48 insertions, 0 deletions
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<int> 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<int> 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 |
