Skip to content

c-variadic: document Clone and Drop instances and require VaArgSafe: Copy#155821

Merged
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
folkertdev:doc-va-list-clone
May 1, 2026
Merged

c-variadic: document Clone and Drop instances and require VaArgSafe: Copy#155821
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
folkertdev:doc-va-list-clone

Conversation

@folkertdev
Copy link
Copy Markdown
Contributor

tracking issue: #44930

Fixing some things that came up in the stabilization PR

r? tgross35
cc @kpreid

@folkertdev folkertdev added the F-c_variadic `#![feature(c_variadic)]` label Apr 26, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 26, 2026

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

Comment thread library/core/src/ffi/va_list.rs Outdated
Comment thread library/core/src/ffi/va_list.rs Outdated
@joshtriplett
Copy link
Copy Markdown
Member

This is still unstable, so it doesn't need an FCP.

LGTM.

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 29, 2026

📌 Commit d143239 has been approved by joshtriplett

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 Apr 29, 2026
/// Corresponds to `va_end` in C.
#[inline] // Avoid codegen when not used to help backends that don't support VaList.
fn drop(&mut self) {
// Call the rust `va_end` intrinsic, which is a no-op and does not map to LLVM `va_end`.
Copy link
Copy Markdown
Member

@programmerjake programmerjake Apr 30, 2026

Choose a reason for hiding this comment

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

this is incorrect on latest nightly, it does call llvm.va_end. see #155697 (comment)

View changes since the review

@programmerjake
Copy link
Copy Markdown
Member

de-approving so this can get looked at:
@bors r-

@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 30, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 30, 2026

This pull request was unapproved.

View changes since this unapproval

@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Apr 30, 2026
@folkertdev
Copy link
Copy Markdown
Contributor Author

huh, that never got updated apparently. It doesn't really matter because it's a no-op, but we should clean that up.

@programmerjake
Copy link
Copy Markdown
Member

huh, that never got updated apparently. It doesn't really matter because it's a no-op, but we should clean that up.

when you or someone else cleans it up, please put the llvm.va_end in VaList::drop and not in the fn f(args: ...) { ... } implementation, that way it properly calls llvm.va_end on cloned VaLists too. that's needed if we gain any targets that need to free memory in va_end.

@folkertdev
Copy link
Copy Markdown
Contributor Author

It's more complicated than that: va_end in C must be called in the same frame that called va_start, hence its ties to .... The situation in LLVM is a bit murky, but so far we've followed that, though the knowledge that it's a no-op gives us some flexibility.

The drop instance is for tracking that a VaList is not used after going out of scope, but that does not need to correspond to va_end being called.

@programmerjake
Copy link
Copy Markdown
Member

It's more complicated than that: va_end in C must be called in the same frame that called va_start, hence its ties to .... The situation in LLVM is a bit murky, but so far we've followed that, though the knowledge that it's a no-op gives us some flexibility.

IMO it's unnecessary to follow the must-be-in-same-function rule, we did talk about that before along with why Drop should call va_end: https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/c-variadics.20in.20const-eval/near/563785065

@folkertdev
Copy link
Copy Markdown
Contributor Author

That's in line with that I'm proposing: the rust va_end is already a no-op, we just didn't remove the llvm backend providing an implementation. If we remove that, the fallback body, a no-op, will be used instead. The Drop implementation calls the rust va_end intrinsic.

The use of the LLVM va_end is tied to ..., and we can remove it too, although given that it's a no-op that isn't crucial.

because a VaList can be cloned, the same c-variadic argument can be read twice and that is only safe if the argument type is copy
it should use the fallback body instead
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 30, 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

@programmerjake let us know if you think the latest commit unblocks this PR at least

@programmerjake
Copy link
Copy Markdown
Member

@programmerjake let us know if you think the latest commit unblocks this PR at least

yeah, now that the comment is accurate I think it's good enough for this PR.

That's in line with that I'm proposing: the rust va_end is already a no-op, we just didn't remove the llvm backend providing an implementation. If we remove that, the fallback body, a no-op, will be used instead. The Drop implementation calls the rust va_end intrinsic.

The use of the LLVM va_end is tied to ..., and we can remove it too, although given that it's a no-op that isn't crucial.

I'm proposing what I thought we had agreed on in the Zulip thread, which is kinda the opposite of what this PR does, though it doesn't matter until we add a target where llvm.va_end is not a no-op.

@folkertdev
Copy link
Copy Markdown
Contributor Author

I'm proposing what I thought we had agreed on in the Zulip thread, which is kinda the opposite of what this PR does, though it doesn't matter until we add a target where llvm.va_end is not a no-op.

I don't really see an LLVM target ever doing that, but perhaps the gcc backend will need it one day for some obscure target. Even so I suspect at that point that we'd pull va_start and va_end into the rust compiler for that target.

@bors r=joshtriplett

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 30, 2026

📌 Commit ac12c69 has been approved by joshtriplett

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 30, 2026
rust-bors Bot pushed a commit that referenced this pull request May 1, 2026
Rollup of 19 pull requests

Successful merges:

 - #155237 (Disentangle AST crates and error crates)
 - #155249 (Fix: On wasm targets, call `panic_in_cleanup` if panic occurs in cleanup)
 - #155853 (Use `_mcount` as the mcount symbol name on RISC-V Linux GNU targets)
 - #155919 (simplify `ast_fragments!`)
 - #155939 (Add feature gate for view_types experiment)
 - #155954 (rustdoc: preserve parent doc cfg for `macro_export` macros)
 - #155974 (add `c_variadic_experimental_arch` feature)
 - #155991 (Catch unwinds from the global ctxt callback to complete queries profiling data in more cases)
 - #156003 (Pass Session to optimize_and_codegen_fat_lto)
 - #153566 (Add suggestion for E0401 on inner const items)
 - #154610 (Suggest public re-exports when a private module makes an import path inaccessible)
 - #155523 (Reorganize `tests/ui/issues/` - 02)
 - #155821 (c-variadic: document `Clone` and `Drop` instances and require `VaArgSafe: Copy`)
 - #155980 (Move `feature*` methods from `parse` mod to `errors` mod.)
 - #155987 (Make lifting infallible)
 - #155988 (tests/run-make/print-cfg: add Android target_env case)
 - #156000 (Fix ICE when using -Zinstrument-mcount and -Clinker-flavor=lld)
 - #156002 (Allow to use `Diagnostic` directly in `SharedContext::emit_lint`)
 - #156015 (rustc-dev-guide subtree update)
@rust-bors rust-bors Bot merged commit 0ab1a47 into rust-lang:main May 1, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone May 1, 2026
rust-timer added a commit that referenced this pull request May 1, 2026
Rollup merge of #155821 - folkertdev:doc-va-list-clone, r=joshtriplett

c-variadic: document `Clone` and `Drop` instances and require `VaArgSafe: Copy`

tracking issue: #44930

Fixing some things that came up in the stabilization PR

r? tgross35
cc @kpreid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

6 participants