diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-04-02 18:39:15 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-02 18:39:15 -0700 |
| commit | 499e2586cba2a7ba2a703b90c459b24620e351ee (patch) | |
| tree | 15ef2e628e15aefec19bfc75b1f90610fa3e1f70 | |
| parent | 38d5ef4764e9271ce2360f42b0759a236cddd9fe (diff) | |
Implement "operator comma" in IR codegen (#472)
Fixes #471
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 9 | ||||
| -rw-r--r-- | tests/bugs/gh-471.slang | 34 | ||||
| -rw-r--r-- | tests/bugs/gh-471.slang.expected.txt | 4 |
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 |
