-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Bounds inference handles casts from uint32 to int32 incorrectly #7807
Comments
Actually my example isn't quite right, because the addition is signed, so the cast of p to int32_t (which is well-defined) happens before the addition, so really what this is a signed integer overflow inside bounds inference that has nothing to do with uint32s. Sigh. |
At root this is the same issue as #3245 |
...does this mean the current state of |
Should have no impact on working code. It was always possible to produce crashing code by tricking bounds inference into doing signed integer overflow. You have to really try though. I think which of these cases will throw a compile-time error vs which will crash at runtime might have changed with the change to cast constant folding. At the very least, the comments are wrong, because casting from a uint32 to an int32 is well-defined now. |
See https://github.com/halide/Halide/blob/main/src/Bounds.cpp#L284
It assumes they can't overflow, but we recently changed that from UB to wrapping semantics in #7769
Now I'm not clear if a case that would have overflowed would have compiled correctly previously (because it would have created a UB expression inside bounds inference), but now it's definitely not right. Here's a failure case that segfaults instead of throwing a bounds error:
The text was updated successfully, but these errors were encountered: