summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/lower-to-ir.cpp9
-rw-r--r--tests/bugs/gh-471.slang34
-rw-r--r--tests/bugs/gh-471.slang.expected.txt4
3 files changed, 47 insertions, 0 deletions
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp
index 57fa55741..5f8428698 100644
--- a/source/slang/lower-to-ir.cpp
+++ b/source/slang/lower-to-ir.cpp
@@ -681,6 +681,15 @@ LoweredValInfo emitCallToDeclRef(
case kIRPseudoOp_Pos:
return LoweredValInfo::simple(args[0]);
+ case kIRPseudoOp_Sequence:
+ // The main effect of "operator comma" is to enforce
+ // sequencing of its operands, but Slang already
+ // implements a strictly left-to-right evaluation
+ // order for function arguments, so in practice we
+ // just need to compile `a, b` to the value of `b`
+ // (because argument evaluation already happened).
+ return LoweredValInfo::simple(args[1]);
+
#define CASE(COMPOUND, OP) \
case COMPOUND: return emitCompoundAssignOp(context, type, OP, argCount, args)
diff --git a/tests/bugs/gh-471.slang b/tests/bugs/gh-471.slang
new file mode 100644
index 000000000..d7123bb4e
--- /dev/null
+++ b/tests/bugs/gh-471.slang
@@ -0,0 +1,34 @@
+//TEST(compute):COMPARE_COMPUTE:
+//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):dxbinding(0),glbinding(0),out
+
+// Test that "operator comma" works as expected
+
+static int a = 0;
+
+int setA(int val)
+{
+ a = val;
+ return 0;
+}
+
+int getA()
+{
+ return a;
+}
+
+int test(int inVal)
+{
+ int x = (setA(inVal), getA());
+ return x * 16;
+}
+
+RWStructuredBuffer<int> outputBuffer : register(u0);
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ int inVal = outputBuffer[tid];
+ int outVal = test(inVal);
+ outputBuffer[tid] = outVal;
+} \ No newline at end of file
diff --git a/tests/bugs/gh-471.slang.expected.txt b/tests/bugs/gh-471.slang.expected.txt
new file mode 100644
index 000000000..39da7d1a9
--- /dev/null
+++ b/tests/bugs/gh-471.slang.expected.txt
@@ -0,0 +1,4 @@
+0
+10
+20
+30