Skip to content

Fix tail calling intrinsics #144815

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

WaffleLapkin
Copy link
Member

@WaffleLapkin WaffleLapkin commented Aug 2, 2025

Tail-calling intrinsics used to ICE/miscompile, this PR fixes that.

The reason I think we should explicitly support calling intrinsics, rather than banning it, is that I don't think we want to expose to users if a function is an intrinsic or not. This is especially relevant with something like std::mem::transmute which is a direct export of the intrinsic, rather than a wrapper function.

The fix has two parts:

  1. For intrinsics which are lowered in mir I've added code to lower them even if they are tail called
  2. For cg_ssa I added code which transforms a tail call to an intrinsic into intrinsic desugaring+ret. This feels like a hack, but I don't really see a better way. (cc @scottmcm, maybe you have an opinion?)

Fixes #144806

@rustbot
Copy link
Collaborator

rustbot commented Aug 2, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Aug 2, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 2, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

added 291 packages in 34s
Running eslint on rustdoc JS files
info: ES-Check: there were no ES version matching errors!  🎉
some tidy checks failed
Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:01:51
  local time: Sat Aug  2 09:34:10 UTC 2025
  network time: Sat, 02 Aug 2025 09:34:10 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@theemathas
Copy link
Contributor

The fact that transmute is an intrinsic is actually already exposed to users. It cannot be coerced to a function pointer.

fn main() {
    let _: unsafe fn(()) = std::mem::transmute::<(), ()>;
}
error[E0308]: cannot coerce intrinsics to function pointers
 --> src/main.rs:2:28
  |
2 |     let _: unsafe fn(()) = std::mem::transmute::<(), ()>;
  |            -------------   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers
  |            |
  |            expected due to this
  |
  = note: expected fn pointer `unsafe fn(())`
                found fn item `unsafe fn(()) {std::intrinsics::transmute::<(), ()>}`

For more information about this error, try `rustc --explain E0308`.

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.

ICE from tail call to transmute
5 participants