Skip to content

implement VaArgSafe for f128 - #161424

Open
folkertdev wants to merge 1 commit into
rust-lang:mainfrom
folkertdev:va-arg-f128
Open

folkertdev wants to merge 1 commit into
rust-lang:mainfrom
folkertdev:va-arg-f128

Conversation

@folkertdev

@folkertdev folkertdev commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

View all comments

On some platforms, especially when long double is IEEE f128 on the platform.

@folkertdev folkertdev added the F-c_variadic `#![feature(c_variadic)]` label Aug 20, 2026
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs 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 Aug 20, 2026
@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors try jobs=test-various,aarch64-apple-,-gnu-nopt-,x86_64-mingw-,aarch64-msvc-*,arm-android

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 20, 2026
implement `VaArgSafe` for `f128`


try-job: test-various
try-job: aarch64-apple-*
try-job: *-gnu-nopt-*
try-job: x86_64-mingw-*
try-job: aarch64-msvc-*
try-job: arm-android

@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 thread library/core/src/ffi/va_list.rs
Comment thread tests/run-make/c-link-to-rust-va-list-fn/checkrust.rs Outdated
@folkertdev
folkertdev marked this pull request as ready for review August 20, 2026 21:52
@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 Aug 20, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors rust-bors Bot 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 Aug 20, 2026
@rust-bors

rust-bors Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

💔 Test for c9719b5 failed: CI. Failed job:

@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors try jobs=test-various,aarch64-apple-,-gnu-nopt-,x86_64-mingw-,aarch64-msvc-*,arm-android

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 21, 2026
implement `VaArgSafe` for `f128`


try-job: test-various
try-job: aarch64-apple-*
try-job: *-gnu-nopt-*
try-job: x86_64-mingw-*
try-job: aarch64-msvc-*
try-job: arm-android
Comment thread library/core/src/ffi/va_list.rs
@rust-bors

rust-bors Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: d5f25c2 (d5f25c2d0c850c37c152ae4a21b215d1c6f7960a)
Base parent: a872286 (a872286d0a1873caec0291ed4304de3170adbe16)

@folkertdev

Copy link
Copy Markdown
Contributor Author

@rustbot ready

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

This comment has been minimized.

Comment thread library/core/src/ffi/va_list.rs Outdated
Comment thread tests/run-make/c-link-to-rust-va-list-fn/test.c Outdated
Comment thread library/core/src/ffi/va_list.rs
@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

Comment thread library/core/src/ffi/va_list.rs Outdated
// Clang 23 hits https://github.com/llvm/llvm-project/issues/217747.
all(target_arch = "x86", not(target_vendor = "apple"), not(target_env = "msvc")),
// PowerPC requires VSX - only little endian has it enabled by default.
all(target_arch = "powerpc64", target_endian = "little"),

@tgross35 tgross35 Sep 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this just use target_feature="vsx"?

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.

I changed it, though core is built without vsx so in practice the result is the same.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought there may have been talks about an elfv2 BE target that requires VSX and thus could have it, but I may be misremembering


#ifdef f128
assert(test_rust(check_list_f128, (f128)-42.0, 0xAAAAAAAA, (f128)-INFINITY) == 0);
#endif

@tgross35 tgross35 Sep 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be better to load a literal for MAX since INFINITY only exercises the top 16 bits. E.g.:

    union cvt128 {
        struct {
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
            uint64_t lo, hi;
#else
            uint64_t hi, lo;
#endif
        } i;
        _Float128 f;
    };
    union cvt128 f128_max;
    f128_max.i.hi = 0x7ffeffffffffffff;
    f128_max.i.lo = 0xffffffffffffffff;
    assert(test_rust(check_list_f128, (f128)-42.0, 0xAAAAAAAA, f128_max.f) == 0);

Kind of annoying that llvm/llvm-project#97335 is still open and we can't just use __FLT128_MAX__.

View changes since the review

Comment thread library/core/src/ffi/va_list.rs Outdated
Comment thread library/core/src/ffi/va_list.rs
Comment thread library/core/src/ffi/va_list.rs Outdated
Comment on lines +418 to +427
// Implement `VaArgSafe` for 128-bit integers on targets where either:
//
// - clang provides `__float128`
// - `long double` is IEEE f128 on the platform.
//
// When updating this cfg, also update the tests to match. Currently this condition
// is duplicated in:
//
// - tests/ui/c-variadic/roundtrip.rs
// - tests/run-make/c-link-to-rust-va-list-fn/checkrust.rs

@tgross35 tgross35 Sep 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I checked against https://c.godbolt.org/z/7WGxKeq9v and everything seems to match up, with the exception of PPC64le. Unless I'm doing something wrong, it seems like Clang doesn't support it but GCC does? If that's accurate, the comment should be updated.

View changes since the review

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.

Clang requires the -mfloat128 option for __float128 on PowerPC.

@rustbot

rustbot commented Sep 17, 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.

@rust-log-analyzer

This comment has been minimized.

Comment thread library/core/src/ffi/va_list.rs Outdated
// Clang 23 hits https://github.com/llvm/llvm-project/issues/217747.
all(target_arch = "x86", not(target_vendor = "apple"), not(target_env = "msvc")),
// PowerPC requires VSX - only little endian has it enabled by default.
all(target_arch = "powerpc64", target_endian = "little"),

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.

I changed it, though core is built without vsx so in practice the result is the same.

Comment on lines +126 to +127
#[unsafe(no_mangle)]
pub static RUST_HAS_F128: c_int = 1;

@folkertdev folkertdev Sep 17, 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 needed on powerpc64 where (at least my) GCC does have f128 support but our baseline does not.

View changes since the review

Comment thread library/core/src/ffi/va_list.rs

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 454d69a has been approved by tgross35

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 17, 2026
@folkertdev

Copy link
Copy Markdown
Contributor Author

This will clash with making VaArgSafe unstable again. I'll just rebase when that merges and put it back in the queue then

@bors r-

@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 17, 2026
@rust-bors

rust-bors Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@rust-bors

rust-bors Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

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

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. A-run-make Area: port run-make Makefiles to rmake.rs F-c_variadic `#![feature(c_variadic)]` 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants