Skip to content

Commit

Permalink
Fix div-by-0 partial eval tests (#3873)
Browse files Browse the repository at this point in the history
According to the spec, division by zero is invalid even if only the rhs
can be constant evaluated for integral types. However, for FP types, it
is only an error if the whole expression can be const-evaled.
  • Loading branch information
sudonatalie authored Jul 23, 2024
1 parent 198d177 commit 964f4b8
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,14 @@ g.test('scalar_vector_out_of_range')
return p.nonOneIndex === 0;
})
.expandWithParams(p => {
// When lhs is a non-const expression, division by zero is only an error for integral types.
const partialDivByZeroIsError = [Type.i32, Type.u32].includes(
scalarTypeOf(kScalarAndVectorTypes[p.rhs])
);
const cases = [
{ leftValue: 42, rightValue: 0, error: true, leftRuntime: false },
{ leftValue: 42, rightValue: 0, error: true, leftRuntime: true },
{ leftValue: 0, rightValue: 0, error: true, leftRuntime: true },
{ leftValue: 42, rightValue: 0, error: partialDivByZeroIsError, leftRuntime: true },
{ leftValue: 0, rightValue: 0, error: partialDivByZeroIsError, leftRuntime: true },
{ leftValue: 0, rightValue: 42, error: false, leftRuntime: false },
];
if (p.lhs === 'i32') {
Expand Down

0 comments on commit 964f4b8

Please sign in to comment.