Skip to content

Commit d213d4b

Browse files
authored
Test compound assignment order of eval (#4606)
Test that the lhs is evaluated before the rhs in a compound assignment statement.
1 parent 21ecca5 commit d213d4b

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/webgpu/listing_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,7 @@
20402040
"webgpu:shader,execution,stage:basic_compute:*": { "subcaseMS": 1.000 },
20412041
"webgpu:shader,execution,stage:basic_render:*": { "subcaseMS": 1.000 },
20422042
"webgpu:shader,execution,statement,compound:decl:*": { "subcaseMS": 29.767 },
2043+
"webgpu:shader,execution,statement,compound:eval_order:*": { "subcaseMS": 54.311 },
20432044
"webgpu:shader,execution,statement,discard:all:*": { "subcaseMS": 36.094 },
20442045
"webgpu:shader,execution,statement,discard:continuing:*": { "subcaseMS": 276.268 },
20452046
"webgpu:shader,execution,statement,discard:derivatives:*": { "subcaseMS": 15.287 },

src/webgpu/shader/execution/statement/compound.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { makeTestGroup } from '../../../../common/framework/test_group.js';
66
import { keysOf } from '../../../../common/util/data_tables.js';
77
import { TypedArrayBufferView } from '../../../../common/util/util.js';
88
import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../../gpu_test.js';
9+
import { runFlowControlTest } from '../flow_control/harness.js';
910

1011
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);
1112

@@ -135,3 +136,33 @@ g.test('decl')
135136
kTests[t.params.case].src
136137
);
137138
});
139+
140+
g.test('eval_order')
141+
.desc('Tests evaluation order of compound assignment, lhs is evaluated before rhs')
142+
.fn(t => {
143+
runFlowControlTest(t, f => ({
144+
entrypoint: `
145+
arr[0] = 41;
146+
${f.expect_order(0)}
147+
arr[idx()] += foo();
148+
${f.expect_order(3)}
149+
if (arr[0] == 42) {
150+
${f.expect_order(4)}
151+
} else {
152+
${f.expect_not_reached()}
153+
}
154+
`,
155+
extra: `
156+
var<private> arr : array<u32, 1>;
157+
fn idx() -> u32 {
158+
${f.expect_order(1)}
159+
return 0;
160+
}
161+
fn foo() -> u32 {
162+
${f.expect_order(2)}
163+
arr[0] = 10;
164+
return 1;
165+
}
166+
`,
167+
}));
168+
});

0 commit comments

Comments
 (0)