Skip to content

Fix deallocation span for locals freed by become tail calls#4943

Open
LaneAsade wants to merge 2 commits intorust-lang:masterfrom
LaneAsade:tail_call_span
Open

Fix deallocation span for locals freed by become tail calls#4943
LaneAsade wants to merge 2 commits intorust-lang:masterfrom
LaneAsade:tail_call_span

Conversation

@LaneAsade
Copy link
Copy Markdown

@LaneAsade LaneAsade commented Apr 6, 2026

This PR fixes #4863

The problem was due to the fact that before_memory_deallocation used current_user_relevant_span to record where an allocation was freed, which produced wrong spans for the locals deallocated by a become tail call.

The solution was to introduce a new field called tail_call_span on MiriMachine which records become expression's span in before_terminator if a TailCall terminator is detected and then use that span in before_memory_deallocation instead of the current one.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 6, 2026

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Apr 6, 2026
@RalfJung
Copy link
Copy Markdown
Member

RalfJung commented May 2, 2026

Thanks for looking into this, and sorry for the slow review!

However, I don't think this logic is correct. Once you set tail_call_span, it will never be unset, so it becomes the deallocation span of all allocations henceforth. That's clearly wrong. And this will be hard to fix since you really only want to affect the deallocations that happen while the TailCall terminator is executed, not anything that happens after.

I think this will require work in the core interpreter. Here on the Miri side, the best we can do are hard-to-get-right and, worse, hard-to-maintain hacks.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels May 2, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 2, 2026

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

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

Labels

S-waiting-on-author Status: Waiting for the PR author to address review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The deallocation span of locals that are deallocated by a tail call become is nonsense

3 participants