Refactor the way cg_ssa handles indirect returns (returns via sret) — Take 2 - #160023
Open
antoyo wants to merge 6 commits into
Open
Refactor the way cg_ssa handles indirect returns (returns via sret) — Take 2#160023antoyo wants to merge 6 commits into
sret) — Take 2#160023antoyo wants to merge 6 commits into
Conversation
…llow for more correct ABI handling in cg_gcc
Co-authored-by: Jubilee <workingjubilee@gmail.com>
Collaborator
|
Some changes occurred in compiler/rustc_codegen_llvm/src/builder/autodiff.rs cc @ZuseZ4
|
Collaborator
|
|
This comment has been minimized.
This comment has been minimized.
antoyo
force-pushed
the
ssa-indirect-return
branch
from
July 27, 2026 17:46
8a2ec6b to
25ec648
Compare
Contributor
Author
|
@bors try |
This comment has been minimized.
This comment has been minimized.
rust-bors Bot
pushed a commit
that referenced
this pull request
Jul 27, 2026
Refactor the way cg_ssa handles indirect returns (returns via `sret`) — Take 2
bjorn3
reviewed
Jul 27, 2026
bjorn3
reviewed
Jul 27, 2026
Contributor
Contributor
|
☔ The latest upstream changes (presumably #159844) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This continues the work that @FractalFir done in #144976.
I managed to make this work, so this confirms the original approach works and is ready to merge.
r? workingjubilee
(assigning the same reviewer as the original PR)
The problem
The current way
cg_ssahandlesPassMode::Indirectis fundamentally incompatible with the requirements of the GCC backend. This is currently worked around in a very brittle way, that breaks on ARM.In order to function correctly,
cg_gccrequires thesret(indirect return) pointer to be treated in a special way.The solution
This PR separates the
sretpointer from all the other arguments, allowing each backend to decide how it wants to handle that pointer. This will allow GCC to do it's own thing, while changing nothing on the LLVM side. Currently, the PR just makes both backends preappend the sret arg, mimicking the previous behaviour.The PR is based on this zulip suggestion.
Assumptions I made.
The PR makes certain assumptions about the ABI handling.
sret. From asking about, it seems like the tail call handling does not currently support indirect returns. So, I did not add support for that.inline_asm_callwill not need thesrethandling code. I am not 100% sure about this, tough.