Skip to content

Treat union fields as aliasing each other in value_analysis - #163425

Open
ojuschugh1 wants to merge 1 commit into
rust-lang:mainfrom
ojuschugh1:jump-threading-fix
Open

ojuschugh1 wants to merge 1 commit into
rust-lang:mainfrom
ojuschugh1:jump-threading-fix

Conversation

@ojuschugh1

@ojuschugh1 ojuschugh1 commented Sep 28, 2026 •

Copy link
Copy Markdown

Fixes #161898

The problem was that for_each_aliasing_place only considered enum variants and the discriminant as aliasing, so writing to one union field left the state of the other fields alone. JumpThreading then threaded the second switchInt on u.a using the value from before u.b = 5, and DataflowConstProp folded the read of u.a to a stale constant in the same way. Union field places have only been in the map since #127087 began collecting places syntactically; before that iter_fields skipped unions.

I made for_each_aliasing_place flood everything under a union as soon as the walk reaches it, since all non-ZST union fields start at offset 0 and overlap. The alternative of not registering places below unions would also work but loses threading on union reads with no write in between.

Added a mir-opt test for each pass.

@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 Sep 28, 2026
@rustbot

rustbot commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @dingxiangfei2009 (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 19 candidates

@rustbot rustbot assigned TaKO8Ki and unassigned dingxiangfei2009 Oct 1, 2026
@ojuschugh1

Copy link
Copy Markdown
Author

Hey @TaKO8Ki @dingxiangfei2009 could you kindly review this PR? Thanks

This branch has not been deployed

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JumpThreading miscompiles union field reads after sibling writes, breaking safe Rust memory safety (missing aliasing flood in value_analysis)

4 participants