Skip to content

implement va_start and va_arg#906

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

implement va_start and va_arg#906
folkertdev wants to merge 1 commit into
rust-lang:masterfrom
folkertdev:va-arg

Conversation

@folkertdev

Copy link
Copy Markdown
Contributor

Comment thread tests/run/variadic.rs

// Tests defining and calling C-variadic functions (reading arguments via `VaList`).
//
// Based on tests/ui/c-variadic/roundtrip.rs from rust-lang/rust.

@antoyo antoyo Jul 12, 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.

Does this test pass?
If so, we can remove it from this file instead.

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.

It should, assuming everything is synchronized. I just removed some i128 logic that just got added a couple of days ago in the main repo and hasn't yet been synchronized back. With the other two PRs merged we can try it in CI here.

@antoyo antoyo 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.

Thanks for your work on this!
One question:

View changes since this review

Comment thread src/intrinsic/mod.rs
let func = self.context.get_builtin_function("__builtin_va_start");

let va_list_type = self.context.new_c_type(CType::VaList);
let va_list = self.context.new_cast(self.location, va_list, va_list_type.make_pointer());

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.

Why is this cast required?
Doesn't va_start take a va_list directly?

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.

Well so there is the GCC __builtin_va_list type and the rust core::ffi::VaList and they are not the same, so on x86_64 you hit

libgccjit.so: error: gcc_jit_context_new_call: mismatching types for argument 1 of
function "__builtin_va_start": assignment to param arg0 (type: __builtin_va_list *)
from &stack_var_1 (type: __int8_t[24]  __attribute__((aligned(8))) *)

Maybe there is a way to tell GCC these are the same? but in any case the cast does the job.

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.

Ok, that makes sense.
It's good as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants