-
Notifications
You must be signed in to change notification settings - Fork 372
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
Inconsistent behavior in irrefutable or-patterns due to UB-removing MIR opt #4237
Comments
This seems to be due to
which originally has:
The read of |
Miri disables all MIR optimizations. So if the compiler then still performs optimizations that remove UB, I think that's a bug in the compiler, yes. mir-opt-level 0 must preserve all UB. |
…chint, r=<try> Do not remove trivial `SwitchInt` with mir-opt-level=0 When mir-opt-level=0, do not optimize out `SwitchInt` terminators that all have the same terminator since it may remove a read which affects miri's ability to detect UB on that operand. cc `@RalfJung` Fixes rust-lang/miri#4237 This affects some tests... I guess I could mark them as `mir-opt-level=1`? Not sure.
…chint, r=<try> Do not remove trivial `SwitchInt` with mir-opt-level=0 When mir-opt-level=0, do not optimize out `SwitchInt` terminators that all have the same terminator since it may remove a read which affects miri's ability to detect UB on that operand. cc `@RalfJung` Fixes rust-lang/miri#4237 This affects some tests... I guess I could mark them as `mir-opt-level=1`? Not sure.
I ran the following code under miri, and it reported no errors:
However, changing the
0
to0..
causes Miri to report undefined behavior:The error reported for the second version of the code:
I expected both versions of the code to behave the same.
Discovered while experimenting with rust-lang/rust#138973
cc @cyrgani @meithecatte
Reproducible on the playground with version
1.87.0-nightly (2025-03-26 a2e63569fd6702ac5dd0)
The text was updated successfully, but these errors were encountered: