-
Notifications
You must be signed in to change notification settings - Fork 995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
naga incorrectly throws multiplication operation overflowed error in expressions involving abstract numerics #6023
Comments
We definitely don't have correct behavior yet with automatic casting of literals; we expect to be pretty close once #4400 is implemented, modulo bugs (which, admittedly, will likely be similar to this one). I won't close this bug as a duplicate, unless @gfx-rs/naga has a strong opinion about it. |
This actually is not related to type conversions. It's simply that the constant evaluator uses |
The spec says:
so I think we need to change all checked_ to wrapped_, at least for (i32, i32). |
I meant other ops like add, or sub. |
Ah my bad, I misunderstood - I'll update my pull request. Thanks! |
I don't think this is actually about casting of abstract types. we appear to handle that correctly. it's actually about overflow handling for non-abstract types during const evaluation
Description
Hi! I think I've found an issue with the way in which naga evaluates certain expressions involving abstract numerics. Naga throws a
multiplication error overflowed
for the following expression but Tint does not.Both tint and naga correctly throw that error for the following expression:
Extra materials
I've spoken to some of the WGSL spec maintainers, who kindly provided the following explanation as for why the first expression should not throw an error:
"The first example is: -1 * i32(-2147483648)
That's type-checked as a multiply with abstract-int on the left, and i32 on the right.
There is no overload of the multiply operator with those two type parameters. There's no up-conversion from i32 to abstract int, and the only viable automatic conversion is to convert the LHS from abstract int to i32. This yields i32 * i32. It's two-s complement arithmetic and therefore wrapping occurs.
In the second example, -1 * -2147483648
It's a multiply of two abstract-ints. There's an overload for that, so the result produces another abstract int, of value 2147483648.
That value is a const-expression, and does not fit in i32, and that causes the error."
The text was updated successfully, but these errors were encountered: