Add run-pass regression test for SimplifyComparisonIntegral non-SSA miscompile#157465
Conversation
…scompile Enabling DestinationPropagation by default let it produce MIR where the comparison destination local is reassigned between the `Eq` and the `SwitchInt` that consumes it. SimplifyComparisonIntegral rewrote `switchInt(_cmp)` into `switchInt(place)` without checking that `_cmp` is written exactly once, using the value from `Eq` and ignoring the later reassignment, which miscompiled at opt-level 2. The fix only applies the optimization to SSA locals, but shipped with mir-opt (MIR-shape) tests only. This adds the missing behavioral run-pass test exercising the end-to-end result.
The bug is that a specific pass miscompiles a specific pattern, so I don't agree with this line of reasoning. Such end-to-end regression tests are vulnerable to spuriously passing because the bug has been reintroduced, but the rest of the compiler has changed. The way you wrote the PR description makes me think you used an LLM to write it. I generally advise against that. Being able to write a good PR description on your own indicates that you actually understand the code. |
Thanks, that makes total sense. I didn't realize a run-pass test could give a false green like that if the MIR shape changes later. Since #150925 already covers this via mir-opt, this PR is definitely redundant. Also to be honest I leaned on AI for the PR description 'cause digging into rustc solo is intimidating and i'm still finding my bearings here. |
|
You don't need to go at this alone, if you don't want to. There's a good community Discord server that has a thread about contributing to the compiler called #rustc-dev : https://discord.gg/rust-lang-community and there's an official Zulip but in my opinion it's more of an office and less of a hangout https://forge.rust-lang.org/platforms/zulip.html |
Regression test for #150904
#142915 enabled
DestinationPropagationby default, which letSimplifyComparisonIntegralsee aswitchInton a comparison local that isreassigned between the
Eqand theswitchInt(a non-SSA local). The passrewrote
switchInt(_cmp)intoswitchInt(place)without checking that_cmpis written exactly once, so it used the value from
Eqand dropped the laterreassignment, miscompiling at
-O.#150925 fixed this by only relating SSA locals, but it shipped with
mir-opt(MIR-shape) tests only - they assert the pass no longer fires on the bad
shapes, but nothing checks the compiled program actually produces the right
result. This adds that behavioral run-pass test, so the end-to-end miscompile
stays covered even if the MIR shape or surrounding passes change.
Runs locally (
./x test tests/ui/mir/simplify-comparison-integral-non-ssa-miscompile.rs→1 passed)r? @saethlin