summaryrefslogtreecommitdiffstats
path: root/tests/bugs
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-09-27 17:11:07 -0700
committerGitHub <noreply@github.com>2024-09-27 17:11:07 -0700
commitafb1405bf7974d714cee10fcce0c61fe28cd075d (patch)
treef4016719071aefc7f8d353defd729c6a542612e9 /tests/bugs
parentf667593e77e18521b7f3bf4f339c2549b5e5eb1b (diff)
Fix l-value computation for subscript call. (#5177)
Diffstat (limited to 'tests/bugs')
-rw-r--r--tests/bugs/gh-4971-2.slang23
-rw-r--r--tests/bugs/gh-4971.slang25
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