Skip to content

Make UB transmutes really UB in LLVM #143718

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Jul 10, 2025

Ralf suggested in #143410 (comment) that UB transmutes shouldn't be trapping, which happened for the one path that PR was changing, but there's another path as well, so this PR changes that other path to match.

r? codegen

Ralf suggested in <rust-lang#143410 (comment)> that UB transmutes shouldn't be trapping, which happened for the one path that PR was changing, but there's another path as well, so this PR changes that other path to match.
@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 Jul 10, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 10, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@RalfJung
Copy link
Member

@nikic is this the best way to indicate "unreachable" to LLVM in the middle of a block? Does LLVM quickly normalize this by making the entire block unreachable or can such an assume cause problems?

@dianqk
Copy link
Member

dianqk commented Jul 10, 2025

@nikic is this the best way to indicate "unreachable" to LLVM in the middle of a block? Does LLVM quickly normalize this by making the entire block unreachable or can such an assume cause problems?

According to https://llvm.org/docs/Frontend/PerformanceTips.html#id11, this should be store i1 true, ptr poison, align 1.

@RalfJung
Copy link
Member

Ah! We should have a helper method for this then.

@scottmcm
Copy link
Member Author

scottmcm commented Jul 10, 2025

Oh, interesting! I'll switch it (both here and in the other spot).

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2025
@dianqk
Copy link
Member

dianqk commented Jul 10, 2025

Ah! We should have a helper method for this then.

Yes. This makes sence to me.
BTW, this reminds me of #127740.

@nikic
Copy link
Contributor

nikic commented Jul 10, 2025

FWIW I don't think it particularly matters how Rust emits this.

@scottmcm
Copy link
Member Author

Well, if nothing else it's reasonable for there to be a method for "I wanted unreachable but not a terminator", so I can do that and if it ends up not mattering which code pattern it is, then fine.

I do think here is different from #127740 because there it was a "runtime" value being passed to the assert, not a constant being created to be passed to it, so there I think it's better to let LLVM normalize, but here where I never specifically wanted an assume in the first place I don't mind just emitting using a different pattern.

So places that need `unreachable` but in the middle of a basic block can call that instead of figuring out the best way to do it.
@scottmcm
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 10, 2025
@WaffleLapkin
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 10, 2025

📌 Commit f5fc872 has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

7 participants