Skip to content

add c-variadic support for x87_f80 - #166510

Open
folkertdev wants to merge 5 commits into
rust-lang:mainfrom
folkertdev:x87_f80-c-variadic
Open

folkertdev wants to merge 5 commits into
rust-lang:mainfrom
folkertdev:x87_f80-c-variadic

Conversation

@folkertdev

Copy link
Copy Markdown
Contributor

tracking issue: #163982

The default paths already have the right behavior. Validated with abi-cafe.

@folkertdev folkertdev added F-c_variadic `#![feature(c_variadic)]` F-c_longdouble `#![feature(c_longdouble)]` labels Nov 24, 2026
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 24, 2026
Comment on lines +254 to +256
// X86_64-NEXT: mov rcx, qword ptr [rax]
// X86_64-NEXT: movzx edx, byte ptr [rax + 8]
// X86_64-NEXT: movzx eax, byte ptr [rax + 9]

@folkertdev folkertdev Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a 10-byte load which is worse assembly than a x87_fp80 load. Totally acceptable, certainly for now.

View changes since the review

@folkertdev

Copy link
Copy Markdown
Contributor Author

r? beetrees

@rustbot

rustbot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

beetrees is currently at their maximum review capacity.
They may take a while to respond.

@folkertdev
folkertdev marked this pull request as ready for review November 24, 2026 19:11
@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 24, 2026

@beetrees beetrees left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR currently results in llvm_type being called on a Rust aggregate (x87_f80) and then the resulting LLVM aggregate being loaded, both of which should be avoided. One solution that would work in this particular case is to substitute cx.type_x87_f80() when layout.is_x87_f80() and let the llvm_value_to_intrinsicresult call at the bottom of codegen_rustc_intrinsic_call store it to the result place. This would work in this particular scenario (and would be fine for this PR), but won't work for other BackendRepr::Memory aggregates like Complex<x87_f80> that can't be represented as a LLVM primitive. The more long-term solution would be to pass result_place to emit_va_arg and directly memcpy the result into it.

Could you also add an codegen-llvm test for the IR emitted by next_arg::<x87_f80>()? Since this is the first Rust aggregate type to have va_arg support it would be good to have a test for what LLVM IR we emit.

View changes since this review

@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 24, 2026
@rustbot

rustbot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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

@rustbot

This comment has been minimized.

@folkertdev folkertdev left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 24, 2026
@folkertdev folkertdev mentioned this pull request Nov 25, 2026
1 of 9 tasks
Comment on lines 212 to 219
// The backend_repr of x87_f80 is not a scalar, so it needs special-casing.
if result_layout.is_x87_f80(self) {
break 'blk emit_va_arg(self, args[0], result_layout);
}

let BackendRepr::Scalar(scalar) = result_layout.backend_repr else {
bug!("the va_arg intrinsic does not support non-scalar types")
};

@beetrees beetrees Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than use a break 'blk, maybe something like:

match result_layout.backend_repr {
    BackendRepr::Scalar(scalar) => {
        match scalar.primitive() {
            ...
        }
    }
    _ if result_layout.is_x87_f80(self) => {}
    _ => bug!("the va_arg intrinsic does not support non-scalar type {result_layout:?}")
}

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumps the indentation by 2 more levels

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting it out into a function is also a bit awkward with all the bug!s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about keeping the break 'blk but still have only a single callsite for emit_va_arg(self, args[0], result_layout)? Something like

            'blk: {
                if result_layout.is_x87_f80(self) {
                    break 'blk;
                }

                let BackendRepr::Scalar(scalar) = result_layout.backend_repr else {
                    bug!("the va_arg intrinsic does not support non-scalar types")
                };
                ...
            }
            emit_va_arg(self, args[0], result_layout)

That would only increase the indentation by one level and would make the control flow easier to follow IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a if let BackendRepr::Scalar(scalar) = result_layout.backend_repr instead of a match would also only increase the indentation by a single level, so that could also be an option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure I've mode the block around.

Comment thread library/core/src/ffi/va_list.rs Resolved
@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 26, 2026

@folkertdev folkertdev left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 212 to 219
// The backend_repr of x87_f80 is not a scalar, so it needs special-casing.
if result_layout.is_x87_f80(self) {
break 'blk emit_va_arg(self, args[0], result_layout);
}

let BackendRepr::Scalar(scalar) = result_layout.backend_repr else {
bug!("the va_arg intrinsic does not support non-scalar types")
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting it out into a function is also a bit awkward with all the bug!s

Comment thread library/core/src/ffi/va_list.rs Resolved
@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 26, 2026
@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

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.

This branch has not been deployed

No deployments
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-c_longdouble `#![feature(c_longdouble)]` F-c_variadic `#![feature(c_variadic)]` 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. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants