Skip to content

Commit 4d82ee7

Browse files
committed
Auto merge of #152701 - jhpratt:rollup-clRaY9x, r=jhpratt
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`)
2 parents d8aec18 + cc26454 commit 4d82ee7

10 files changed

Lines changed: 216 additions & 4 deletions

File tree

src/alloc_addresses/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
184184
}
185185
#[cfg(not(all(unix, feature = "native-lib")))]
186186
AllocKind::Function => dummy_alloc(params),
187-
AllocKind::VTable => dummy_alloc(params),
187+
AllocKind::VTable | AllocKind::VaList => dummy_alloc(params),
188188
AllocKind::TypeId | AllocKind::Dead => unreachable!(),
189189
};
190190
// We don't have to expose this pointer yet, we do that in `prepare_for_native_call`.

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> {
655655
dcx.log_protector();
656656
}
657657
},
658-
AllocKind::Function | AllocKind::VTable | AllocKind::TypeId | AllocKind::Dead => {
658+
AllocKind::Function | AllocKind::VTable | AllocKind::TypeId | AllocKind::Dead | AllocKind::VaList => {
659659
// No stacked borrows on these allocations.
660660
}
661661
}
@@ -1014,7 +1014,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10141014
trace!("Stacked Borrows tag {tag:?} exposed in {alloc_id:?}");
10151015
alloc_extra.borrow_tracker_sb().borrow_mut().exposed_tags.insert(tag);
10161016
}
1017-
AllocKind::Function | AllocKind::VTable | AllocKind::TypeId | AllocKind::Dead => {
1017+
AllocKind::Function
1018+
| AllocKind::VTable
1019+
| AllocKind::TypeId
1020+
| AllocKind::Dead
1021+
| AllocKind::VaList => {
10181022
// No stacked borrows on these allocations.
10191023
}
10201024
}

src/borrow_tracker/tree_borrows/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
577577
let protected = protected_tags.contains_key(&tag);
578578
alloc_extra.borrow_tracker_tb().borrow_mut().expose_tag(tag, protected);
579579
}
580-
AllocKind::Function | AllocKind::VTable | AllocKind::TypeId | AllocKind::Dead => {
580+
AllocKind::Function
581+
| AllocKind::VTable
582+
| AllocKind::TypeId
583+
| AllocKind::Dead
584+
| AllocKind::VaList => {
581585
// No tree borrows on these allocations.
582586
}
583587
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(c_variadic)]
2+
3+
unsafe extern "C" fn helper(_: i32, _: ...) {}
4+
5+
fn main() {
6+
unsafe {
7+
let f = helper as *const ();
8+
let f = std::mem::transmute::<_, unsafe extern "C" fn(...)>(f);
9+
10+
f(1);
11+
//~^ ERROR: Undefined Behavior
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: Undefined Behavior: calling a C-variadic function with 0 fixed arguments, but the function expects 1
2+
--> tests/fail/c-variadic-mismatch-count.rs:LL:CC
3+
|
4+
LL | f(1);
5+
| ^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
10+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
11+
12+
error: aborting due to 1 previous error
13+

tests/fail/c-variadic-mismatch.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(c_variadic)]
2+
3+
unsafe extern "C" fn helper(_: i32, _: ...) {}
4+
5+
fn main() {
6+
unsafe {
7+
let f = helper as *const ();
8+
let f = std::mem::transmute::<_, unsafe extern "C" fn(_: i32, _: i64)>(f);
9+
10+
f(1i32, 1i64);
11+
//~^ ERROR: Undefined Behavior: calling a function where the caller and callee disagree on whether the function is C-variadic
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: Undefined Behavior: calling a function where the caller and callee disagree on whether the function is C-variadic
2+
--> tests/fail/c-variadic-mismatch.rs:LL:CC
3+
|
4+
LL | f(1i32, 1i64);
5+
| ^^^^^^^^^^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
10+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
11+
12+
error: aborting due to 1 previous error
13+

tests/fail/c-variadic.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(c_variadic)]
2+
3+
//@error-in-other-file: Undefined Behavior: more C-variadic arguments read than were passed
4+
5+
fn read_too_many() {
6+
unsafe extern "C" fn variadic(mut ap: ...) {
7+
ap.arg::<i32>();
8+
}
9+
10+
unsafe { variadic() };
11+
}
12+
13+
fn main() {
14+
read_too_many();
15+
}

tests/fail/c-variadic.stderr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: Undefined Behavior: more C-variadic arguments read than were passed
2+
--> RUSTLIB/core/src/ffi/va_list.rs:LL:CC
3+
|
4+
LL | unsafe { va_arg(self) }
5+
| ^^^^^^^^^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: stack backtrace:
10+
0: std::ffi::VaList::<'_>::arg
11+
at RUSTLIB/core/src/ffi/va_list.rs:LL:CC
12+
1: read_too_many::variadic
13+
at tests/fail/c-variadic.rs:LL:CC
14+
2: read_too_many
15+
at tests/fail/c-variadic.rs:LL:CC
16+
3: main
17+
at tests/fail/c-variadic.rs:LL:CC
18+
19+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
20+
21+
error: aborting due to 1 previous error
22+

tests/pass/c-variadic.rs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#![feature(c_variadic)]
2+
3+
use std::ffi::{CStr, VaList, c_char, c_double, c_int, c_long};
4+
5+
fn ignores_arguments() {
6+
unsafe extern "C" fn variadic(_: ...) {}
7+
8+
unsafe { variadic() };
9+
unsafe { variadic(1, 2, 3) };
10+
}
11+
12+
fn echo() {
13+
unsafe extern "C" fn variadic(mut ap: ...) -> i32 {
14+
ap.arg()
15+
}
16+
17+
assert_eq!(unsafe { variadic(1) }, 1);
18+
assert_eq!(unsafe { variadic(3, 2, 1) }, 3);
19+
}
20+
21+
fn forward_by_val() {
22+
unsafe fn helper(mut ap: VaList) -> i32 {
23+
ap.arg()
24+
}
25+
26+
unsafe extern "C" fn variadic(ap: ...) -> i32 {
27+
helper(ap)
28+
}
29+
30+
assert_eq!(unsafe { variadic(1) }, 1);
31+
assert_eq!(unsafe { variadic(3, 2, 1) }, 3);
32+
}
33+
34+
fn forward_by_ref() {
35+
unsafe fn helper(ap: &mut VaList) -> i32 {
36+
ap.arg()
37+
}
38+
39+
unsafe extern "C" fn variadic(mut ap: ...) -> i32 {
40+
helper(&mut ap)
41+
}
42+
43+
assert_eq!(unsafe { variadic(1) }, 1);
44+
assert_eq!(unsafe { variadic(3, 2, 1) }, 3);
45+
}
46+
47+
#[allow(improper_ctypes_definitions)]
48+
fn nested() {
49+
unsafe fn helper(mut ap1: VaList, mut ap2: VaList) -> (i32, i32) {
50+
(ap1.arg(), ap2.arg())
51+
}
52+
53+
unsafe extern "C" fn variadic2(ap1: VaList, ap2: ...) -> (i32, i32) {
54+
helper(ap1, ap2)
55+
}
56+
57+
unsafe extern "C" fn variadic1(ap1: ...) -> (i32, i32) {
58+
variadic2(ap1, 2, 2)
59+
}
60+
61+
assert_eq!(unsafe { variadic1(1) }, (1, 2));
62+
63+
let (a, b) = unsafe { variadic1(1, 1) };
64+
65+
assert_eq!(a, 1);
66+
assert_eq!(b, 2);
67+
}
68+
69+
fn various_types() {
70+
unsafe extern "C" fn check_list_2(mut ap: ...) {
71+
macro_rules! continue_if {
72+
($cond:expr) => {
73+
if !($cond) {
74+
panic!();
75+
}
76+
};
77+
}
78+
79+
unsafe fn compare_c_str(ptr: *const c_char, val: &str) -> bool {
80+
match CStr::from_ptr(ptr).to_str() {
81+
Ok(cstr) => cstr == val,
82+
Err(_) => panic!(),
83+
}
84+
}
85+
86+
continue_if!(ap.arg::<c_double>().floor() == 3.14f64.floor());
87+
continue_if!(ap.arg::<c_long>() == 12);
88+
continue_if!(ap.arg::<c_int>() == 'a' as c_int);
89+
continue_if!(ap.arg::<c_double>().floor() == 6.18f64.floor());
90+
continue_if!(compare_c_str(ap.arg::<*const c_char>(), "Hello"));
91+
continue_if!(ap.arg::<c_int>() == 42);
92+
continue_if!(compare_c_str(ap.arg::<*const c_char>(), "World"));
93+
}
94+
95+
unsafe {
96+
check_list_2(
97+
3.14 as c_double,
98+
12 as c_long,
99+
b'a' as c_int,
100+
6.28 as c_double,
101+
c"Hello".as_ptr(),
102+
42 as c_int,
103+
c"World".as_ptr(),
104+
);
105+
}
106+
}
107+
108+
fn main() {
109+
ignores_arguments();
110+
echo();
111+
forward_by_val();
112+
forward_by_ref();
113+
nested();
114+
various_types();
115+
}

0 commit comments

Comments
 (0)