Skip to content

Commit 06354f4

Browse files
Rollup merge of #156086 - RalfJung:next-arg-miri-errs, r=folkertdev
VaList::next_arg: track_caller for better Miri errors The test diff should explain why this is better. :) r? @folkertdev
2 parents b8c24b1 + 9cdf5dc commit 06354f4

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

library/core/src/ffi/va_list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ impl<'f> VaList<'f> {
422422
/// [`c_void`]: core::ffi::c_void
423423
#[inline] // Avoid codegen when not used to help backends that don't support VaList.
424424
#[rustc_const_unstable(feature = "const_c_variadic", issue = "151787")]
425+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
425426
pub const unsafe fn next_arg<T: VaArgSafe>(&mut self) -> T {
426427
// SAFETY: the caller must uphold the safety contract for `va_arg`.
427428
unsafe { va_arg(self) }

src/tools/miri/tests/fail/c-variadic.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#![feature(c_variadic)]
22

3-
//@error-in-other-file: Undefined Behavior: more C-variadic arguments read than were passed
4-
53
fn read_too_many() {
64
unsafe extern "C" fn variadic(mut ap: ...) {
7-
ap.next_arg::<i32>();
5+
ap.next_arg::<i32>(); //~ERROR: more C-variadic arguments read than were passed
86
}
97

108
unsafe { variadic() };

src/tools/miri/tests/fail/c-variadic.stderr

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
error: Undefined Behavior: more C-variadic arguments read than were passed
2-
--> RUSTLIB/core/src/ffi/va_list.rs:LL:CC
2+
--> tests/fail/c-variadic.rs:LL:CC
33
|
4-
LL | unsafe { va_arg(self) }
5-
| ^^^^^^^^^^^^ Undefined Behavior occurred here
4+
LL | ap.next_arg::<i32>();
5+
| ^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= note: stack backtrace:
10-
0: std::ffi::VaList::<'_>::next_arg
11-
at RUSTLIB/core/src/ffi/va_list.rs:LL:CC
12-
1: read_too_many::variadic
10+
0: read_too_many::variadic
1311
at tests/fail/c-variadic.rs:LL:CC
14-
2: read_too_many
12+
1: read_too_many
1513
at tests/fail/c-variadic.rs:LL:CC
16-
3: main
14+
2: main
1715
at tests/fail/c-variadic.rs:LL:CC
1816

1917
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

0 commit comments

Comments
 (0)