Skip to content

support c-variadic functions in rustc_const_eval#150601

Merged
rust-bors[bot] merged 6 commits intorust-lang:mainfrom
folkertdev:c-variadic-const-eval
Feb 16, 2026
Merged

support c-variadic functions in rustc_const_eval#150601
rust-bors[bot] merged 6 commits intorust-lang:mainfrom
folkertdev:c-variadic-const-eval

Conversation

@folkertdev
Copy link
Contributor

@folkertdev folkertdev commented Jan 2, 2026

tracking issue: #44930

The new GlobalAlloc::VaList is used to create an AllocId that represents the variable argument list of a frame. The allocation itself does not store any data, all we need is the unique identifier.

The actual variable argument list is stored in Memory, and keyed by the AllocId. The Frame also stores this AllocId, so that when a frame is popped, it can deallocate the variable arguments.

At "runtime" a VaList value stores a pointer to the global allocation in its first bytes. The provenance on this pointer can be used to retrieve its AllocId, and the offset of the pointer is used to store the index of the next argument to read from the variable argument list.

Miri does not yet support va_arg, but I think that can be done separetely?

r? @RalfJung
cc @workingjubilee

@folkertdev folkertdev added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) F-c_variadic `#![feature(c_variadic)]` labels Jan 2, 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 Jan 2, 2026
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from d30044f to 5f98625 Compare January 2, 2026 18:57
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from 5f98625 to 3368321 Compare January 2, 2026 19:09
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from 3368321 to 41a34bc Compare January 2, 2026 19:32
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from 41a34bc to 8608ba7 Compare January 2, 2026 20:51
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from 8608ba7 to 207b032 Compare January 2, 2026 21:58
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 4, 2026

☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts.

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from 207b032 to 1794556 Compare January 5, 2026 10:30
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch 2 times, most recently from b297adc to c081ba3 Compare January 5, 2026 11:14
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from c081ba3 to 293ba18 Compare January 5, 2026 12:25
@folkertdev folkertdev marked this pull request as ready for review January 5, 2026 17:34
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 5, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 5, 2026

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 5, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 10, 2026

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

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from fa8908e to 05768c3 Compare February 13, 2026 10:52
Comment on lines +782 to +788
if arg_mplace.layout.ty != dest.layout.ty {
throw_unsup_format!(
"va_arg type mismatch: requested `{}`, but next argument is `{}`",
dest.layout.ty,
arg_mplace.layout.ty
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we do a type comparison, would it be more idiomatic to use layout_compat That would let through usize to u32/u64 conversions and I think pointer casts as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a bit less straightforward to describe than a simple equality though.

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest to open an issue about this, and keep the most strict check for now. I am not entirely certain that layout_compat is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's just go with the simple rule for now then.

Comment on lines 353 to 360
// The check for the DefKind is so that we don't request the fn_sig of a closure.
// Otherwise, we hit:
//
// DefId(1:180 ~ std[269c]::rt::lang_start_internal::{closure#0}) does not have a "fn_sig"
let (fixed_count, callee_c_variadic_args) =
if matches!(self.tcx.def_kind(instance.def_id()), DefKind::Fn)
&& let callee_fn_sig = self.tcx.fn_sig(instance.def_id()).skip_binder()
&& callee_fn_sig.c_variadic()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, those changes look good to me.

@folkertdev
Copy link
Contributor Author

CI made it, so, is this done?

@RalfJung
Copy link
Member

RalfJung commented Feb 14, 2026 via email

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from 3c69b50 to 44c2b10 Compare February 14, 2026 16:23
@rustbot
Copy link
Collaborator

rustbot commented Feb 14, 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
Contributor Author

Squashed it down into 6 commits, roughly by area of code that was touched.

@rust-bors

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from 44c2b10 to f2e4a2f Compare February 14, 2026 21:55
@folkertdev
Copy link
Contributor Author

@RalfJung a formality at this point but this needs your final (explicit) blessing

@RalfJung
Copy link
Member

I'm aware, I just had plans this weekend that kept me away from my laptop. ;)

#[primary_span]
pub span: Span,
pub kind: ConstContext,
pub non_or_conditionally: &'static str,
Copy link
Member

Choose a reason for hiding this comment

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

This field does not seem to be actually used? It showed up in the range-diff, seems to have been added during the rebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I had to rebase over the changes to error messages/fluent. Not fun. Fixed this now.

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

(submitting a review to get a diff marker)

View changes since this review

@folkertdev folkertdev force-pushed the c-variadic-const-eval branch from f2e4a2f to 981dacc Compare February 15, 2026 18:54
@RalfJung
Copy link
Member

Looks good, thanks for the patience!
@bors r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 16, 2026

📌 Commit 981dacc has been approved by RalfJung

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 Feb 16, 2026
rust-bors bot pushed a commit that referenced this pull request Feb 16, 2026
Rollup of 6 pull requests

Successful merges:

 - #148206 (Deduplicated float tests and unified in floats/mod.rs)
 - #150601 (support c-variadic functions in `rustc_const_eval`)
 - #152103 (Consider captures to be used by closures that unwind)
 - #152296 (Port `rust_nonnull_optimization_guaranteed` and `rustc_do_not_const_check` to the new attribute parser)
 - #152648 (Remove timing assertion from `oneshot::send_before_recv_timeout`)
 - #152686 (bootstrap: Inline the `is_tool` check for setting `-Zforce-unstable-if-unmarked`)

Failed merges:

 - #152512 (core: Implement feature `float_exact_integer_constants`)
@rust-bors rust-bors bot merged commit 494c6da into rust-lang:main Feb 16, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 16, 2026
rust-timer added a commit that referenced this pull request Feb 16, 2026
Rollup merge of #150601 - folkertdev:c-variadic-const-eval, r=RalfJung

support c-variadic functions in `rustc_const_eval`

tracking issue: #44930

The new `GlobalAlloc::VaList` is used to create an `AllocId` that represents the variable argument list of a frame. The allocation itself does not store any data, all we need is the unique identifier.

The actual variable argument list is stored in `Memory`, and keyed by the `AllocId`. The `Frame` also stores this `AllocId`, so that when a frame is popped, it can deallocate the variable arguments.

At "runtime" a `VaList` value stores a pointer to the global allocation in its first bytes. The provenance on this pointer can be used to retrieve its `AllocId`, and the offset of the pointer is used to store the index of the next argument to read from the variable argument list.

Miri does not yet support `va_arg`, but I think that can be done separetely?

r? @RalfJung
cc @workingjubilee
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Feb 17, 2026
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#148206 (Deduplicated float tests and unified in floats/mod.rs)
 - rust-lang/rust#150601 (support c-variadic functions in `rustc_const_eval`)
 - rust-lang/rust#152103 (Consider captures to be used by closures that unwind)
 - rust-lang/rust#152296 (Port `rust_nonnull_optimization_guaranteed` and `rustc_do_not_const_check` to the new attribute parser)
 - rust-lang/rust#152648 (Remove timing assertion from `oneshot::send_before_recv_timeout`)
 - rust-lang/rust#152686 (bootstrap: Inline the `is_tool` check for setting `-Zforce-unstable-if-unmarked`)

Failed merges:

 - rust-lang/rust#152512 (core: Implement feature `float_exact_integer_constants`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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.

4 participants