Skip to content

c-variadic: initialize the copied VaList in const-eval#157977

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
folkertdev:miri-zero-valist
Jun 20, 2026
Merged

c-variadic: initialize the copied VaList in const-eval#157977
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
folkertdev:miri-zero-valist

Conversation

@folkertdev

@folkertdev folkertdev commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

View all comments

Properly initialize the result of VaList::clone in rustc_const_eval.

r? RalfJung
cc @theemathas

@folkertdev folkertdev added the F-c_variadic `#![feature(c_variadic)]` label Jun 16, 2026
@rustbot

rustbot commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

miri is developed in its own repository. If possible, consider making this change to rust-lang/miri instead.

cc @rust-lang/miri

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@rustbot rustbot added 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. labels Jun 16, 2026
@rustbot

rustbot commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

Comment on lines +108 to +116
fn clone() {
pub unsafe extern "C" fn clone_the_va_list(args: ...) {
// The implicit `drop` will catch a `VaList` that isn't properly initialized.
let _ = args.clone();
}

unsafe { clone_the_va_list(1i32, 2i32) }
}

@theemathas theemathas Jun 16, 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.

Could you also add tests to make sure that interleaving next_arg() with clone() in various combinations work correctly (give correct return values in miri)?

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.

Sure, I added some.

@rust-log-analyzer

This comment has been minimized.

@folkertdev

Copy link
Copy Markdown
Contributor Author

Hmm, we hit an interesting case here where we do have a fallback body, but that fallback is not valid for miri (but it is for llvm, gcc and cranelift) because it doesn't update the internal bookkeeping. So using -Zmiri-force-intrinsic-fallback fails.

How should I work around this?

@RalfJung

Copy link
Copy Markdown
Member

How should I work around this?

Skip those tests under cfg!(force_intrinsic_fallback).

@RalfJung RalfJung left a comment

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.

Thanks! I just have some nits and clarification questions.

@rustbot author

View changes since this review

Comment thread compiler/rustc_const_eval/src/interpret/intrinsics.rs Outdated
Comment thread src/tools/miri/tests/pass/c-variadic.rs Outdated
fn clone_and_advance() {
if cfg!(force_intrinsic_fallback) {
// Skip this test when we use the fallback bodies, the fallback body does
// not hook into the Miri bookkeeping that we need to detect UB.

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 test does not have UB though? I don't understand this comment.

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.

With the flag enabled Miri thinks there is UB though

https://triage.rust-lang.org/gha-logs/rust-lang/rust/81717608108

We then duplicate a VaList by just duplicating the bits (a memcpy) and that is fine for LLVM but for Miri we don't set up the allocations correctly in that case.

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.

Yes, I understand that you do need to skip the test when fallback bodies are on. But the comment currently doesn't make sense.

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.

It's also kind of bad that "force-intrinsic-fallbacks" reports incorrect UB. That's not supposed to happen.

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.

Let's add something like this to the va_copy fallback body

// This fallback body exploits the fact that our codegen backends all just a plain
// memcpy to duplicate VaList. This assumption is wrong for Miri.
assert!(!cfg!(miri), "fallback body is incorrect under Miri");

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.

We could also remove the fallback body when cfg(miri)? Or does miri use the pre-built core?

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.

There's no nice way to disable the body with cfg.

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 seems like a good test to run natively. Can you add //@run-native at the top of this file?

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.

Adding that annotation makes the test fail, without any good way to debug it. Based on https://triage.rust-lang.org/gha-logs/rust-lang/rust/81980686843 it looks like the assert is triggered, so somehow the native test sets cfg!(miri) to true but also uses the fallback?

Is there some flag I'm missing for seeing the actual cause of the failure?

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.

I think the cause was the other clone test also hitting the assert. Still, the debugging experience here could be better...

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 behaves exactly like regular rustc ui tests. So not sure what we could do on the debugging side.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 17, 2026
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 17, 2026
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

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

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev left a comment

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.

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.

I think the cause was the other clone test also hitting the assert. Still, the debugging experience here could be better...

@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 Jun 18, 2026
@RalfJung

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7c497ef 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 Jun 20, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 20, 2026
c-variadic: initialize the copied `VaList` in const-eval



Properly initialize the result of `VaList::clone` in `rustc_const_eval`.

r? RalfJung
cc @theemathas
@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 20, 2026
@rust-bors

rust-bors Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 4f5af41 failed: CI. Failed job:

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
  NO_DOWNLOAD_CI_LLVM: 1
  WIX: /d/a/rust/rust/wix
##[endgroup]
    Updating crates.io index
error: failed to get `icu_normalizer` as a dependency of package `idna_adapter v1.2.0`
    ... which satisfies dependency `idna_adapter = "^1"` of package `idna v1.0.3`
    ... which satisfies dependency `idna = "^1.0"` of package `cookie_store v0.21.1`
    ... which satisfies dependency `cookie_store = "^0.21.1"` of package `ureq v3.0.8`
    ... which satisfies dependency `ureq = "^3"` of package `citool v0.1.0 (D:\a\rust\rust\src\ci\citool)`

Caused by:
  failed to load source for dependency `icu_normalizer`

Caused by:
  unable to update registry `crates-io`

Caused by:
  download of ic/u_/icu_normalizer failed

Caused by:
  curl failed

Caused by:

@RalfJung

Copy link
Copy Markdown
Member

@bors retry

@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 Jun 20, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 20, 2026
@rust-bors

rust-bors Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: RalfJung
Duration: 3h 9m 48s
Pushing 4008bbd to main...

@rust-bors rust-bors Bot merged commit 4008bbd into rust-lang:main Jun 20, 2026
14 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor
What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 8c75e93 (parent) -> 4008bbd (this PR)

Test differences

No test diffs found

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 4008bbdf34b583ce44a467043aae3703afc0a76f --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-gnu-gcc-core-tests: 13m 25s -> 5m 46s (-57.0%)
  2. dist-x86_64-freebsd: 1h 33m -> 56m 47s (-39.4%)
  3. x86_64-rust-for-linux: 50m 27s -> 34m 28s (-31.7%)
  4. dist-aarch64-apple: 1h 36m -> 2h 6m (+31.2%)
  5. x86_64-gnu-stable: 1h 50m -> 2h 21m (+28.0%)
  6. dist-x86_64-msvc: 2h 10m -> 1h 35m (-27.1%)
  7. dist-powerpc64-linux-musl: 1h 15m -> 1h 34m (+24.7%)
  8. dist-armv7-linux: 1h 12m -> 1h 30m (+24.6%)
  9. dist-x86_64-msvc-alt: 2h 5m -> 2h 32m (+21.9%)
  10. x86_64-gnu-nopt: 2h 22m -> 1h 53m (-20.2%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (4008bbd): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.2%, 0.3%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 480.613s -> 487.822s (1.50%)
Artifact size: 390.68 MiB -> 391.12 MiB (0.11%)

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)]` merged-by-bors This PR was explicitly merged by bors. T-compiler Relevant to the compiler 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