Skip to content

Support u128/i128 c-variadic arguments#155429

Merged
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
folkertdev:c-variadic-i128
Jul 10, 2026
Merged

Support u128/i128 c-variadic arguments#155429
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
folkertdev:c-variadic-i128

Conversation

@folkertdev

@folkertdev folkertdev commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

View all comments

The restriction on u128 is kind of arbitrary, so let's see what it would take to support it.

r? @ghost

@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-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. labels Apr 17, 2026
@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors try jobs=dist-various-1,dist-various-2,aarch64-apple,x86_64-mingw-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 17, 2026
Support `u128`/`i128` c-variadic arguments


try-job: dist-various-1
try-job: dist-various-2
try-job: aarch64-apple
try-job: x86_64-mingw-1
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-i128 branch 2 times, most recently from 3f2ff65 to 5e8c8b5 Compare April 17, 2026 13:27
@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors try jobs=dist-various-1,dist-various-2,aarch64-apple,x86_64-mingw-1

rust-bors Bot pushed a commit that referenced this pull request Apr 17, 2026
Support `u128`/`i128` c-variadic arguments


try-job: dist-various-1
try-job: dist-various-2
try-job: aarch64-apple
try-job: x86_64-mingw-1
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@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 Apr 17, 2026
@rust-bors

rust-bors Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

💔 Test for d3bd26f failed: CI. Failed job:

@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors try jobs=dist-various-1,dist-various-2,aarch64-apple,x86_64-mingw-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 17, 2026
Support `u128`/`i128` c-variadic arguments


try-job: dist-various-1
try-job: dist-various-2
try-job: aarch64-apple
try-job: x86_64-mingw-1
@rust-bors

rust-bors Bot commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: d505291 (d50529125c96155f22b48fab34b00ab49c79dcad, parent: f29256dd1420dc681bf4956e3012ffe9eccdc7e7)

@rustbot

This comment has been minimized.

Comment thread library/core/src/ffi/va_list.rs Outdated
Comment thread compiler/rustc_codegen_llvm/src/va_arg.rs Outdated
Primitive::Int(integer, _) => match integer {
Integer::I8 | Integer::I16 => unreachable!(),
Integer::I32 | Integer::I64 => { /* fall through */ }
Integer::I128 => return Align::EIGHT,

@folkertdev folkertdev Apr 21, 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.

It has custom behavior, the va_arg implementation for powerpc64 is here

https://github.com/llvm/llvm-project/blob/c7eea85b8046660f0a1fd4a1c5c41b44475f8caf/clang/lib/CodeGen/Targets/PPC.cpp#L998

and it uses the implementation here

https://github.com/llvm/llvm-project/blob/c7eea85b8046660f0a1fd4a1c5c41b44475f8caf/clang/lib/CodeGen/Targets/PPC.cpp#L765

The logic falls through to the last line for i128, returning 8. For f128 it curiously does use an alignment of 16, so I've just added that already because it would be easy to miss down the line.

View changes since the review

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.

That's Weird. Kinda almost want to ask if that's intentional. I suppose this is currently correct, at least...? ...but does gcc agree...?

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.

GCC does agree, see https://godbolt.org/z/eW3daf7rG. 24 is added to the pointer, with an alignment of 16 you'd expect to see 32 to be added. 24 = 8 (for the u32 plus padding) + 16 (for the i128).

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.

Ah thanks for digging that up! Such a weird assembly language, to notate immediate adds with their own instruction and use juxtaposition for addition...

Comment thread library/core/src/ffi/va_list.rs
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 9, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 9, 2026
…ingjubilee

Support `u128`/`i128` c-variadic arguments

The restriction on `u128` is kind of arbitrary, so let's see what it would take to support it.

r? @ghost
rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
…uwer

Rollup of 17 pull requests

Successful merges:

 - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets)
 - #158541 (Move `std::io::Write` to `core::io`)
 - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`)
 - #155429 (Support `u128`/`i128` c-variadic arguments)
 - #156370 (Reject linked dylib EII default overrides)
 - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s)
 - #158535 (Support `#[track_caller]` on EII declarations)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158988 (Redo `TokenStreamIter`)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158739 (view-types: HIR lowering)
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158886 (Add documentation for the `no_std` attribute)
 - #158951 (Merge three `MaxUniverse`s into one)
 - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places")
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 9, 2026
…ingjubilee

Support `u128`/`i128` c-variadic arguments

The restriction on `u128` is kind of arbitrary, so let's see what it would take to support it.

r? @ghost
@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors r-

#159024 (comment)

@rust-bors

rust-bors Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#159024), which was unapproved.

View changes since this unapproval

On platforms where `clang` defines `__int128`.
@rustbot

rustbot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/tools/cargo

cc @ehuss

@rust-bors

rust-bors Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ A new commit de4f96e41055bc24ff31a85aa5fc01a806bb044d was pushed.

This PR was contained in a rollup (#159024), which was closed.

@rustbot

rustbot commented Jul 9, 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.

@rustbot

This comment has been minimized.

@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors try jobs=x86_64-gnu-nopt,dist-various-1,dist-various-2,aarch64-apple,x86_64-mingw-1

@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: b5658f2 (b5658f2c88ed3161e8ba8532a11712e0eac41763)
Base parent: 3664b37 (3664b37017c529cad0f0ed259769f15743c21a6a)

@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors r=workingjubilee iffy

@rust-bors

rust-bors Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 3ba3735 has been approved by workingjubilee

It is now in the queue for this repository.

@folkertdev

Copy link
Copy Markdown
Contributor Author

hmm

@bors iffy

@rust-bors

rust-bors Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Unknown command "iffy". Run @bors help or go to https://bors.rust-lang.org/help to see available commands.

@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors rollup=iffy

@tgross35

Copy link
Copy Markdown
Contributor

Thank you @workingjubilee for taking over the review I never got to

Comment on lines +390 to +391
#[cfg(not(any(target_arch = "wasm32", target_abi = "x32", target_pointer_width = "64")))]
compile_error!("unexpected target architecture for 128-bit c-variadic");

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.

This broke AArch64 ILP32 targets (aarch64-unknown-linux-gnu_ilp32, aarch64_be-unknown-linux-gnu_ilp32, arm64_32-apple-watchos).

https://github.com/taiki-e/atomic-maybe-uninit/actions/runs/29137306574/job/86504296151#step:4:244

  error: unexpected target architecture for 128-bit c-variadic
     --> /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ffi/va_list.rs:391:9
      |
  391 |         compile_error!("unexpected target architecture for 128-bit c-variadic");
      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

(By the way, although they aren't builtin targets, similar ABIs exist for other architectures as well.)

It might make more sense to use something like any(target_arch = "wasm32", target_arch = "x86_64", all(target_pointer_width = "64", any(target_arch = "aarch64", ...))) for the cfg in cfg_select. (I use approach like that in my crates e.g., (atomic-maybe-uninit, portable-atomic).)

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.

Can you make a PR for that? It's really just a backup check for us not providing the functionality where we can't guarantee it'll work.

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.

Filed #159167.

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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants