Skip to content

Conversation

@InvalidPathException
Copy link
Contributor

@InvalidPathException InvalidPathException commented Oct 29, 2025

Fixes #148239 #144986

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.

Added two UI tests to demonstrate each case.

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 :)

@rustbot

This comment has been minimized.

@InvalidPathException
Copy link
Contributor Author

InvalidPathException commented Oct 29, 2025

Made changes to address existing comments, the generated IR for tests/ui/explicit-tail-calls/become-indirect-return.rs is provided below:
shouldbegood.txt

Lines 110-125

; become_indirect_return::dispatch
; Function Attrs: noinline uwtable
define internal void @_ZN22become_indirect_return8dispatch17hd1719c44a86d65c3E(ptr sret([24 x i8]) align 1 %_0, ptr align 8 %param) unnamed_addr #1 {
start:
; call become_indirect_return::op_dummy
  musttail call void @_ZN22become_indirect_return8op_dummy17h31e000dd5109bff4E(ptr sret([24 x i8]) align 1 %_0, ptr align 8 %param)
  ret void
}

; become_indirect_return::op_dummy
; Function Attrs: noinline uwtable
define internal void @_ZN22become_indirect_return8op_dummy17h31e000dd5109bff4E(ptr sret([24 x i8]) align 1 %_0, ptr align 8 %_param) unnamed_addr #1 {
start:
  call void @llvm.memset.p0.i64(ptr align 1 %_0, i8 1, i64 24, i1 false)
  ret void

@rust-log-analyzer

This comment has been minimized.

@InvalidPathException
Copy link
Contributor Author

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 :)

How can we properly test this if run-pass causes gcc tests to fail? I cannot find an existing example on how to handle this (other than making the tests type check only).

@bjorn3
Copy link
Member

bjorn3 commented Oct 29, 2025

You can add an //@ ignore-backends: gcc annotation to disable the test with GCC.

@InvalidPathException
Copy link
Contributor Author

Tested with a real use case here and it compiles and runs fine. Did not notice any issue + verified it is not lowered to unoptimized recursive calls in IR.

@WaffleLapkin
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 1, 2025

📌 Commit 52959a8 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 Nov 1, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 1, 2025
…fleLapkin

rustc_codegen: fix musttail returns for cast/indirect ABIs

Fixes rust-lang#148239 rust-lang#144986

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.

Added two UI tests to demonstrate each case.

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

r? theemathas
bors added a commit that referenced this pull request Nov 1, 2025
Rollup of 8 pull requests

Successful merges:

 - #147137 (Mention crate being analyzed in query description)
 - #148099 (Prepare to move debugger discovery from compiletest to bootstrap)
 - #148194 (compiletest: Remove `cleanup_debug_info_options`)
 - #148199 (compiletest: Don't modify `testpaths` when creating aux contexts)
 - #148240 (rustc_codegen: fix musttail returns for cast/indirect ABIs)
 - #148247 (Remove two special cases from reachable_non_generics)
 - #148290 (Do not emit solver errors that contain error types)
 - #148362 (docs: makes a note about possible building  `rustc 1.91.0 + host tools` for win7)

r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 2, 2025
…fleLapkin

rustc_codegen: fix musttail returns for cast/indirect ABIs

Fixes rust-lang#148239 rust-lang#144986

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.

Added two UI tests to demonstrate each case.

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

r? theemathas
bors added a commit that referenced this pull request Nov 2, 2025
Rollup of 9 pull requests

Successful merges:

 - #147947 (Implement `strip_circumfix` lib feature)
 - #148170 (split definition and use site hidden tys)
 - #148194 (compiletest: Remove `cleanup_debug_info_options`)
 - #148199 (compiletest: Don't modify `testpaths` when creating aux contexts)
 - #148240 (rustc_codegen: fix musttail returns for cast/indirect ABIs)
 - #148290 (Do not emit solver errors that contain error types)
 - #148357 (temporary-lifetime-extension.rs test works in all editions)
 - #148362 (docs: makes a note about possible building  `rustc 1.91.0 + host tools` for win7)
 - #148367 (Use --print host-tuple to get the host)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r- #148382 (comment)

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 2, 2025
@InvalidPathException
Copy link
Contributor 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 Nov 2, 2025
@WaffleLapkin
Copy link
Member

WaffleLapkin commented Nov 2, 2025

@InvalidPathException I think you forgot to push the changes addressing CI failure.
@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 Nov 2, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 2, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@InvalidPathException
Copy link
Contributor Author

@InvalidPathException I think you forgot to push the changes addressing CI failure. @rustbot author

72c9762f500ec24b017506d01427594f34bce250 This should fix it, no?

@InvalidPathException
Copy link
Contributor Author

Might be because the comment was timestamped weirdly so the timeline became unclear. Not sure why it's dated "in the future".
@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 Nov 2, 2025
@WaffleLapkin
Copy link
Member

my bad, didn't notice the commit in all the backlinks 🤦🏻
@bors r+

@bors
Copy link
Collaborator

bors commented Nov 2, 2025

📌 Commit 72c9762 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 Nov 2, 2025
bors added a commit that referenced this pull request Nov 3, 2025
Rollup of 5 pull requests

Successful merges:

 - #144194 (Provide additional context to errors involving const traits)
 - #148232 (ci: add runners for vanilla LLVM 21)
 - #148240 (rustc_codegen: fix musttail returns for cast/indirect ABIs)
 - #148247 (Remove a special case and move another one out of reachable_non_generics)
 - #148370 (Point at inner item when it uses generic type param from outer item or `Self`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f8ff304 into rust-lang:master Nov 3, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 3, 2025
rust-timer added a commit that referenced this pull request Nov 3, 2025
Rollup merge of #148240 - InvalidPathException:master, r=WaffleLapkin

rustc_codegen: fix musttail returns for cast/indirect ABIs

Fixes #148239 #144986

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.

Added two UI tests to demonstrate each case.

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

r? theemathas
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Nov 4, 2025
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#144194 (Provide additional context to errors involving const traits)
 - rust-lang/rust#148232 (ci: add runners for vanilla LLVM 21)
 - rust-lang/rust#148240 (rustc_codegen: fix musttail returns for cast/indirect ABIs)
 - rust-lang/rust#148247 (Remove a special case and move another one out of reachable_non_generics)
 - rust-lang/rust#148370 (Point at inner item when it uses generic type param from outer item or `Self`)

r? `@ghost`
`@rustbot` modify labels: rollup
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-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.

explicit_tail_calls misorders sret argument, breaking ABI for become calls Using #[inline(always)] and become together leads to LLVM failure

7 participants