Skip to content

Commit

Permalink
Add override test for short circuiting in arrays (#4183)
Browse files Browse the repository at this point in the history
Co-authored-by: Peter McNeeley <petermcneeley@google.com>
  • Loading branch information
petermcneeleychromium and Peter McNeeley authored Feb 11, 2025
1 parent 769869f commit fb608e6
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,37 @@ fn main() {

t.expectCompileResult(t.params.control, code);
});

g.test('array_override')
.desc(
`
Validates that override initializing expressions works in conjunction with arrays
`
)
.params(u =>
u.combine('op', ['&&', '||']).combine('a_val', [0, 1]).combine('b_val', [0, 1]).beginSubcases()
)
.fn(t => {
const code = `
override a_val:i32;
override b_val:i32;
override bad_size = (a_val - 10);
override good_size = (b_val + 10);
var<workgroup> zero_array:array<i32, select(bad_size, good_size, a_val == 1 ${t.params.op} b_val == 1 )>;
`;
const code_entry = `let foo = zero_array[0];`;
const op_a_or = kLhsForShortCircuit[t.params.op];
const constants: Record<string, number> = {};
constants['a_val'] = t.params.a_val;
constants['b_val'] = t.params.b_val;
const cond_val = op_a_or
? t.params.a_val === 1 || t.params.b_val === 1
: t.params.a_val === 1 && t.params.b_val === 1;

t.expectPipelineResult({
expectedResult: cond_val,
code,
constants,
statements: [code_entry],
});
});

0 comments on commit fb608e6

Please sign in to comment.