Skip to content

Conversation

@RalfJung
Copy link
Member

Alternative to #144933: when invoking a tail call with a non-scalar argument, we need to delay freeing the caller's local variables until after the callee is initialized, so that we can copy things from the caller to the callee.

Fixes #144820... but as the FIXMEs in the code show, it's not clear to me whether these are the right semantics.
r? @WaffleLapkin

@rustbot
Copy link
Collaborator

rustbot commented Dec 28, 2025

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

The Miri subtree was changed

cc @rust-lang/miri

@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 Dec 28, 2025
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the interpret-tail-call branch from 3604bf5 to 0d2a400 Compare December 29, 2025 08:49
@bors
Copy link
Collaborator

bors commented Jan 1, 2026

☔ The latest upstream changes (presumably #150565) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung RalfJung force-pushed the interpret-tail-call branch from 0d2a400 to 1bccfe8 Compare January 2, 2026 09:54
@rustbot

This comment has been minimized.

@folkertdev
Copy link
Contributor

I looked into this some at #144855 (comment). In summary, I believe that a tail call that uses an argument that is PassMode::Indirect { on_stack: false } fundamentally cannot work. That value lives on the caller's stack, and the callee has no space where that argument can be stored. The argument stack value becomes dead upon the call.

Supporting PassMode::Indirect { on_stack: true } should be possible once LLVM supports it on more targets. As of LLVM 21 at least aarch64 and s390x support that, riscv and x86 don't yet.

@RalfJung RalfJung force-pushed the interpret-tail-call branch from 1bccfe8 to b3bdf0f Compare January 11, 2026 18:12
@rustbot
Copy link
Collaborator

rustbot commented Jan 11, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@RalfJung
Copy link
Member Author

RalfJung commented Jan 11, 2026

Thanks, I had not seen that issue! What a mess. Whatever rules we come up with should be portable to all targets...

Anyway, that's mostly orthogonal to what we do in the interpreter. Fixing the order in which we copy arguments and deallocate the old locals still makes sense IMO.

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.

Miri reports UB for explicit tail call with by-value non-ZST struct parameter

6 participants