Skip to content

Copy an object passed by value a word at a time on i386 - #3710

Merged
tamnd merged 2 commits into
mainfrom
codegen/i386-byval-copy
Oct 16, 2026
Merged

tamnd merged 2 commits into
mainfrom
codegen/i386-byval-copy

Conversation

@tamnd

@tamnd tamnd commented Oct 16, 2026

Copy link
Copy Markdown
Owner

On i386 a call that passed a large structure by value copied it into the outgoing area with memcpy. The copy's own three arguments go on the stack too, at the bottom of the area the call is being written into, so they overwrote the arguments already stored there. 00204 of c-testsuite passes two large structures and printed garbage for the first, which is why both i686 rung 0 jobs fail on main.

A convention with fewer than three argument registers, which is every i386 one, now copies a word at a time however large the object is. GCC makes no library call while it sets up a call's arguments either. This also takes away the nested memcpy call that ld.lld refused to link as "cannot be preempted" when the callee was a local function.

On the Linux box 00204 now matches the expected output at -O0 and -O2, with and without PIE, rung 0 passes 440 of 440 on both i686-linux-gnu and x86_64-linux-gnu, and the rucc-codegen tests and clippy pass. A new test checks that a 4096 byte object passed on i386 is copied with no call to memcpy.

A call that passes a large structure by value on i386 copied it with memcpy into the outgoing area. The copy's own three arguments go on the stack there too, at the bottom of the area the call is being written into, so they overwrote the arguments already stored. 00204 of c-testsuite passed two large structures and printed garbage for the first. A convention with fewer than three argument registers now copies a word at a time however large the object is, which is what GCC does too.
@tamnd tamnd added kind/bug Crash, wrong diagnostic, or a valid program rejected area/backend Instruction selection, scheduling, block layout, frames area/abi The four ABIs, struct layout, TLS, and the runtime labels Oct 16, 2026
@tamnd
tamnd merged commit 5c0d46d into main Oct 16, 2026
@tamnd
tamnd deleted the codegen/i386-byval-copy branch October 16, 2026 23:10
@tamnd tamnd mentioned this pull request Oct 16, 2026
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/abi The four ABIs, struct layout, TLS, and the runtime area/backend Instruction selection, scheduling, block layout, frames kind/bug Crash, wrong diagnostic, or a valid program rejected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant