Skip to content

Support u128/i128 c-variadic arguments#155429

Open
folkertdev wants to merge 2 commits into
rust-lang:mainfrom
folkertdev:c-variadic-i128
Open

Support u128/i128 c-variadic arguments#155429
folkertdev wants to merge 2 commits into
rust-lang:mainfrom
folkertdev:c-variadic-i128

Conversation

@folkertdev
Copy link
Copy Markdown
Contributor

@folkertdev folkertdev commented Apr 17, 2026

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
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 17, 2026

💔 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
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 18, 2026

☀️ 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 on lines +359 to +383
crate::cfg_select! {
target_pointer_width = "32" => {
// GCC says <https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/_005f_005fint128.html>
//
// > There is no support in GCC for expressing an integer constant of type __int128 for targets
// > with long long integer less than 128 bits wide.
}
target_env = "msvc" => {
// Per https://learn.microsoft.com/en-us/cpp/cpp/data-type-ranges?view=msvc-170, __int128 is
// not recognized by msvc.
}
any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64",
target_arch = "s390x",
target_arch = "powerpc64"
) => {
unsafe impl VaArgSafe for i128 {}
unsafe impl VaArgSafe for u128 {}
}
_ => {
}
}
Copy link
Copy Markdown
Contributor Author

@folkertdev folkertdev Apr 21, 2026

Choose a reason for hiding this comment

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

cc @Amanieu @joshtriplett @workingjubilee thoughts on this as an initial set of targets to support i128 varargs on?

View changes since the review

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,
Copy link
Copy Markdown
Contributor Author

@folkertdev folkertdev Apr 21, 2026

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

Comment thread library/core/src/ffi/va_list.rs
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 25, 2026

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

@folkertdev
Copy link
Copy Markdown
Contributor Author

may as well

@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 25, 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.

@rust-log-analyzer

This comment has been minimized.

) -> &'ll Value {
if layout.layout.align.abi > src_align {
let tmp = bx.alloca(layout.layout.size(), layout.layout.align().abi);
let tmp = bx.alloca_with_ty(layout);
Copy link
Copy Markdown
Contributor Author

@folkertdev folkertdev Apr 25, 2026

Choose a reason for hiding this comment

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

Using a typed alloca solves an issue with the memcpy not being optimized out, see llvm/llvm-project#194158. Normally rust type erases allocas (e.g. [16 x i8]) and that confuses LLVM apparently.

View changes since the review

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 25, 2026

💔 Test for 9d4c015 failed: CI. Failed job:

@rustbot

This comment has been minimized.

@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 25, 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.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 25, 2026

☀️ Try build successful (CI)
Build commit: aee82fa (aee82fa5d127ed3da73b856690b5b55cbfd0efd3, parent: 9838411cb723b60dc62b1625751075c4d933b992)

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-i128 branch 2 times, most recently from 2db94a6 to 7d2a6d2 Compare April 26, 2026 17:01
@rust-bors

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 29, 2026

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.

@folkertdev
Copy link
Copy Markdown
Contributor Author

didn't realize I had never pushed/marked as ready.

@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 May 29, 2026
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-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