Skip to content

Conversation

@InvalidPathException
Copy link

@InvalidPathException InvalidPathException commented Oct 29, 2025

Fixes #148239

(Hopefully!)

Explicit tail calls trigger bug! for any callee whose ABI returns via PassMode::Cast, and we forgot to to forward the hidden sret out-pointer when the ABI requested an indirect return. The former causes ICE, the latter produced malformed IR (wrong codegen) if the return value is large enough to need sret.

Updated the musttail helper to accept cast-mode returns, made it so that we pass the return pointer through the tail-call path, and added UI tests that cover both cases.

Added two UI tests (should they be elsewhere?)

This is my first time contributing, please do check if I did it right.

r? theemathas

@rustbot
Copy link
Collaborator

rustbot commented Oct 29, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-explicit_tail_calls `#![feature(explicit_tail_calls)]` 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 Oct 29, 2025
@WaffleLapkin WaffleLapkin self-assigned this Oct 29, 2025
@WaffleLapkin
Copy link
Member

The best practice I'm usually trying to follow is: add tests in a separate commit (and make them "pass" there, possibly with known bug annotations, etc). That way the second commit with the impl clearly shows how the behavior changed, in the tests' diff.

If you have time I'd recommend you do the same here (tip: jj makes splitting/modifying commits easy).

And congrats on your first contribution! I'll try to review your PR shortly :)

@@ -0,0 +1,19 @@
//@ check-pass
#![allow(incomplete_features)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use expect instead, so that we remember to remoce this when the feature stops being incomplete.

"tail calls to functions with indirect returns cannot store into a destination"
),
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not merge this into the match kind below that does make_return_dest for the non-tail call case already?

ReturnDest::Nothing => {}
_ => bug!(
"tail calls to functions with indirect returns cannot store into a destination"
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct. make_return_dest only returns something other than ReturnDest::Nothing for indirect returns when the destination is an LocalRef::PendingOperand, but _0 should be a LocalRef::Place for indirect returns and tail calls shouldn't use any destination other than _0.

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-explicit_tail_calls `#![feature(explicit_tail_calls)]` 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.

explicit_tail_calls misorders sret argument, breaking ABI for become calls

4 participants