Skip to content

Add run-pass regression test for SimplifyComparisonIntegral non-SSA miscompile#157465

Closed
Vastargazing wants to merge 1 commit into
rust-lang:mainfrom
Vastargazing:tests/simplify-comparison-integral-non-ssa-miscompile
Closed

Add run-pass regression test for SimplifyComparisonIntegral non-SSA miscompile#157465
Vastargazing wants to merge 1 commit into
rust-lang:mainfrom
Vastargazing:tests/simplify-comparison-integral-non-ssa-miscompile

Conversation

@Vastargazing

@Vastargazing Vastargazing commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Regression test for #150904

#142915 enabled DestinationPropagation by default, which let
SimplifyComparisonIntegral see a switchInt on a comparison local that is
reassigned between the Eq and the switchInt (a non-SSA local). The pass
rewrote switchInt(_cmp) into switchInt(place) without checking that _cmp
is written exactly once, so it used the value from Eq and dropped the later
reassignment, 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.rs1 passed)

r? @saethlin

…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.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 5, 2026
@saethlin

saethlin commented Jun 7, 2026

Copy link
Copy Markdown
Member

This adds that behavioral run-pass test, so the end-to-end miscompile
stays covered even if the MIR shape or surrounding passes change.

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.

@saethlin saethlin closed this Jun 7, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 7, 2026
@Vastargazing

Copy link
Copy Markdown
Contributor Author

This adds that behavioral run-pass test, so the end-to-end miscompile
stays covered even if the MIR shape or surrounding passes change.

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.

@Vastargazing Vastargazing deleted the tests/simplify-comparison-integral-non-ssa-miscompile branch June 8, 2026 17:16
@saethlin

saethlin commented Jun 8, 2026

Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants