Skip to content

Commit 0b60d9f

Browse files
authored
Merge pull request #2263 from BoxyUwU/rustc-pull2
Rustc pull
2 parents d9a91b1 + b18a6b4 commit 0b60d9f

21 files changed

+169
-53
lines changed

src/intrinsics/atomic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
189189
let place = this.deref_pointer(place)?;
190190
let rhs = this.read_immediate(rhs)?;
191191

192-
if !place.layout.ty.is_integral() && !place.layout.ty.is_unsafe_ptr() {
192+
if !place.layout.ty.is_integral() && !place.layout.ty.is_raw_ptr() {
193193
span_bug!(
194194
this.cur_span(),
195195
"atomic arithmetic operations only work on integer and raw pointer types",

src/intrinsics/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,60 +145,60 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
145145
this.write_scalar(Scalar::from_bool(branch), dest)?;
146146
}
147147

148-
"floorf16" | "ceilf16" | "truncf16" | "roundf16" | "rintf16" => {
148+
"floorf16" | "ceilf16" | "truncf16" | "roundf16" | "round_ties_even_f16" => {
149149
let [f] = check_arg_count(args)?;
150150
let f = this.read_scalar(f)?.to_f16()?;
151151
let mode = match intrinsic_name {
152152
"floorf16" => Round::TowardNegative,
153153
"ceilf16" => Round::TowardPositive,
154154
"truncf16" => Round::TowardZero,
155155
"roundf16" => Round::NearestTiesToAway,
156-
"rintf16" => Round::NearestTiesToEven,
156+
"round_ties_even_f16" => Round::NearestTiesToEven,
157157
_ => bug!(),
158158
};
159159
let res = f.round_to_integral(mode).value;
160160
let res = this.adjust_nan(res, &[f]);
161161
this.write_scalar(res, dest)?;
162162
}
163-
"floorf32" | "ceilf32" | "truncf32" | "roundf32" | "rintf32" => {
163+
"floorf32" | "ceilf32" | "truncf32" | "roundf32" | "round_ties_even_f32" => {
164164
let [f] = check_arg_count(args)?;
165165
let f = this.read_scalar(f)?.to_f32()?;
166166
let mode = match intrinsic_name {
167167
"floorf32" => Round::TowardNegative,
168168
"ceilf32" => Round::TowardPositive,
169169
"truncf32" => Round::TowardZero,
170170
"roundf32" => Round::NearestTiesToAway,
171-
"rintf32" => Round::NearestTiesToEven,
171+
"round_ties_even_f32" => Round::NearestTiesToEven,
172172
_ => bug!(),
173173
};
174174
let res = f.round_to_integral(mode).value;
175175
let res = this.adjust_nan(res, &[f]);
176176
this.write_scalar(res, dest)?;
177177
}
178-
"floorf64" | "ceilf64" | "truncf64" | "roundf64" | "rintf64" => {
178+
"floorf64" | "ceilf64" | "truncf64" | "roundf64" | "round_ties_even_f64" => {
179179
let [f] = check_arg_count(args)?;
180180
let f = this.read_scalar(f)?.to_f64()?;
181181
let mode = match intrinsic_name {
182182
"floorf64" => Round::TowardNegative,
183183
"ceilf64" => Round::TowardPositive,
184184
"truncf64" => Round::TowardZero,
185185
"roundf64" => Round::NearestTiesToAway,
186-
"rintf64" => Round::NearestTiesToEven,
186+
"round_ties_even_f64" => Round::NearestTiesToEven,
187187
_ => bug!(),
188188
};
189189
let res = f.round_to_integral(mode).value;
190190
let res = this.adjust_nan(res, &[f]);
191191
this.write_scalar(res, dest)?;
192192
}
193-
"floorf128" | "ceilf128" | "truncf128" | "roundf128" | "rintf128" => {
193+
"floorf128" | "ceilf128" | "truncf128" | "roundf128" | "round_ties_even_f128" => {
194194
let [f] = check_arg_count(args)?;
195195
let f = this.read_scalar(f)?.to_f128()?;
196196
let mode = match intrinsic_name {
197197
"floorf128" => Round::TowardNegative,
198198
"ceilf128" => Round::TowardPositive,
199199
"truncf128" => Round::TowardZero,
200200
"roundf128" => Round::NearestTiesToAway,
201-
"rintf128" => Round::NearestTiesToEven,
201+
"round_ties_even_f128" => Round::NearestTiesToEven,
202202
_ => bug!(),
203203
};
204204
let res = f.round_to_integral(mode).value;

src/intrinsics/simd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
633633
this.write_immediate(*val, &dest)?;
634634
}
635635
}
636-
"shuffle_generic" => {
636+
"shuffle_const_generic" => {
637637
let [left, right] = check_arg_count(args)?;
638638
let (left, left_len) = this.project_to_simd(left)?;
639639
let (right, right_len) = this.project_to_simd(right)?;
@@ -657,7 +657,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
657657
this.read_immediate(&this.project_index(&right, right_idx)?)?
658658
} else {
659659
throw_ub_format!(
660-
"`simd_shuffle_generic` index {src_index} is out-of-bounds for 2 vectors with length {dest_len}"
660+
"`simd_shuffle_const_generic` index {src_index} is out-of-bounds for 2 vectors with length {dest_len}"
661661
);
662662
};
663663
this.write_immediate(*val, &dest)?;

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#![cfg_attr(bootstrap, feature(trait_upcasting))]
21
#![feature(rustc_private)]
32
#![feature(cell_update)]
43
#![feature(float_gamma)]
4+
#![feature(float_erf)]
55
#![feature(map_try_insert)]
66
#![feature(never_type)]
77
#![feature(try_blocks)]
@@ -15,8 +15,6 @@
1515
#![feature(unqualified_local_imports)]
1616
#![feature(derive_coerce_pointee)]
1717
#![feature(arbitrary_self_types)]
18-
#![feature(unsigned_is_multiple_of)]
19-
#![feature(extract_if)]
2018
// Configure clippy and other lints
2119
#![allow(
2220
clippy::collapsible_else_if,

src/operator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5252
// Some more operations are possible with atomics.
5353
// The return value always has the provenance of the *left* operand.
5454
Add | Sub | BitOr | BitAnd | BitXor => {
55-
assert!(left.layout.ty.is_unsafe_ptr());
56-
assert!(right.layout.ty.is_unsafe_ptr());
55+
assert!(left.layout.ty.is_raw_ptr());
56+
assert!(right.layout.ty.is_raw_ptr());
5757
let ptr = left.to_scalar().to_pointer(this)?;
5858
// We do the actual operation with usize-typed scalars.
5959
let left = ImmTy::from_uint(ptr.addr().bytes(), this.machine.layouts.usize);

src/shims/foreign_items.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
742742
| "log1pf"
743743
| "expm1f"
744744
| "tgammaf"
745+
| "erff"
746+
| "erfcf"
745747
=> {
746748
let [f] = this.check_shim(abi, Conv::C , link_name, args)?;
747749
let f = this.read_scalar(f)?.to_f32()?;
@@ -759,6 +761,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
759761
"log1pf" => f_host.ln_1p(),
760762
"expm1f" => f_host.exp_m1(),
761763
"tgammaf" => f_host.gamma(),
764+
"erff" => f_host.erf(),
765+
"erfcf" => f_host.erfc(),
762766
_ => bug!(),
763767
};
764768
let res = res.to_soft();
@@ -799,6 +803,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
799803
| "log1p"
800804
| "expm1"
801805
| "tgamma"
806+
| "erf"
807+
| "erfc"
802808
=> {
803809
let [f] = this.check_shim(abi, Conv::C , link_name, args)?;
804810
let f = this.read_scalar(f)?.to_f64()?;
@@ -816,6 +822,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
816822
"log1p" => f_host.ln_1p(),
817823
"expm1" => f_host.exp_m1(),
818824
"tgamma" => f_host.gamma(),
825+
"erf" => f_host.erf(),
826+
"erfc" => f_host.erfc(),
819827
_ => bug!(),
820828
};
821829
let res = res.to_soft();
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//@normalize-stderr-test: "\d+ < \d+" -> "$$ADDR < $$ADDR"
2-
#![feature(ptr_sub_ptr)]
3-
42
fn main() {
53
let arr = [0u8; 8];
64
let ptr1 = arr.as_ptr();
75
let ptr2 = ptr1.wrapping_add(4);
8-
let _val = unsafe { ptr1.sub_ptr(ptr2) }; //~ERROR: first pointer has smaller address than second
6+
let _val = unsafe { ptr1.offset_from_unsigned(ptr2) }; //~ERROR: first pointer has smaller address than second
97
}

tests/fail/intrinsics/ptr_offset_from_unsigned_neg.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: `ptr_offset_from_unsigned` called when first pointer has smaller address than second: $ADDR < $ADDR
22
--> tests/fail/intrinsics/ptr_offset_from_unsigned_neg.rs:LL:CC
33
|
4-
LL | let _val = unsafe { ptr1.sub_ptr(ptr2) };
5-
| ^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called when first pointer has smaller address than second: $ADDR < $ADDR
4+
LL | let _val = unsafe { ptr1.offset_from_unsigned(ptr2) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called when first pointer has smaller address than second: $ADDR < $ADDR
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

tests/fail/panic/panic_abort1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@error-in-other-file: the program aborted execution
22
//@normalize-stderr-test: "\| +\^+" -> "| ^"
3-
//@normalize-stderr-test: "libc::abort\(\);|core::intrinsics::abort\(\);" -> "ABORT();"
3+
//@normalize-stderr-test: "unsafe \{ libc::abort\(\); \}|core::intrinsics::abort\(\);" -> "ABORT();"
44
//@compile-flags: -C panic=abort
55

66
fn main() {

tests/fail/panic/panic_abort2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@error-in-other-file: the program aborted execution
22
//@normalize-stderr-test: "\| +\^+" -> "| ^"
3-
//@normalize-stderr-test: "libc::abort\(\);|core::intrinsics::abort\(\);" -> "ABORT();"
3+
//@normalize-stderr-test: "unsafe \{ libc::abort\(\); \}|core::intrinsics::abort\(\);" -> "ABORT();"
44
//@compile-flags: -C panic=abort
55

66
fn main() {

tests/fail/panic/panic_abort3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@error-in-other-file: the program aborted execution
22
//@normalize-stderr-test: "\| +\^+" -> "| ^"
3-
//@normalize-stderr-test: "libc::abort\(\);|core::intrinsics::abort\(\);" -> "ABORT();"
3+
//@normalize-stderr-test: "unsafe \{ libc::abort\(\); \}|core::intrinsics::abort\(\);" -> "ABORT();"
44
//@compile-flags: -C panic=abort
55

66
fn main() {

tests/fail/panic/panic_abort4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@error-in-other-file: the program aborted execution
22
//@normalize-stderr-test: "\| +\^+" -> "| ^"
3-
//@normalize-stderr-test: "libc::abort\(\);|core::intrinsics::abort\(\);" -> "ABORT();"
3+
//@normalize-stderr-test: "unsafe \{ libc::abort\(\); \}|core::intrinsics::abort\(\);" -> "ABORT();"
44
//@compile-flags: -C panic=abort
55

66
fn main() {

tests/fail/ptr_swap_nonoverlapping.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! This is a regression test for <https://github.com/rust-lang/miri/issues/4188>: The precondition
2+
//! check in `ptr::swap_nonoverlapping` was incorrectly disabled in Miri.
3+
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
4+
//@normalize-stderr-test: "\| +\^+" -> "| ^"
5+
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
6+
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
7+
//@error-in-other-file: aborted execution
8+
9+
fn main() {
10+
let mut data = 0usize;
11+
let ptr = std::ptr::addr_of_mut!(data);
12+
unsafe {
13+
std::ptr::swap_nonoverlapping(ptr, ptr, 1);
14+
}
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
3+
unsafe precondition(s) violated: ptr::swap_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap
4+
5+
This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.
6+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
7+
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
8+
thread caused non-unwinding panic. aborting.
9+
error: abnormal termination: the program aborted execution
10+
--> RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
11+
|
12+
LL | ABORT();
13+
| ^ the program aborted execution
14+
|
15+
= note: BACKTRACE:
16+
= note: inside `std::sys::pal::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
17+
= note: inside `std::panicking::rust_panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC
18+
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
19+
= note: inside `std::sys::backtrace::__rust_end_short_backtrace::<{closure@std::panicking::begin_panic_handler::{closure#0}}, !>` at RUSTLIB/std/src/sys/backtrace.rs:LL:CC
20+
= note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
21+
= note: inside `core::panicking::panic_nounwind` at RUSTLIB/core/src/panicking.rs:LL:CC
22+
= note: inside `std::ptr::swap_nonoverlapping::precondition_check` at RUSTLIB/core/src/ub_checks.rs:LL:CC
23+
= note: inside `std::ptr::swap_nonoverlapping::<usize>` at RUSTLIB/core/src/ub_checks.rs:LL:CC
24+
note: inside `main`
25+
--> tests/fail/ptr_swap_nonoverlapping.rs:LL:CC
26+
|
27+
LL | std::ptr::swap_nonoverlapping(ptr, ptr, 1);
28+
| ^
29+
30+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
31+
32+
error: aborting due to 1 previous error
33+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Test that transmuting from `&dyn Trait<fn(&'static ())>` to `&dyn Trait<for<'a> fn(&'a ())>` is UB.
2+
//
3+
// The vtable of `() as Trait<fn(&'static ())>` and `() as Trait<for<'a> fn(&'a ())>` can have
4+
// different entries and, because in the former the entry for `foo` is vacant, this test will
5+
// segfault at runtime.
6+
7+
trait Trait<U> {
8+
fn foo(&self)
9+
where
10+
U: HigherRanked,
11+
{
12+
}
13+
}
14+
impl<T, U> Trait<U> for T {}
15+
16+
trait HigherRanked {}
17+
impl HigherRanked for for<'a> fn(&'a ()) {}
18+
19+
// 2nd candidate is required so that selecting `(): Trait<fn(&'static ())>` will
20+
// evaluate the candidates and fail the leak check instead of returning the
21+
// only applicable candidate.
22+
trait Unsatisfied {}
23+
impl<T: Unsatisfied> HigherRanked for T {}
24+
25+
fn main() {
26+
let x: &dyn Trait<fn(&'static ())> = &();
27+
let y: &dyn Trait<for<'a> fn(&'a ())> = unsafe { std::mem::transmute(x) };
28+
//~^ ERROR: wrong trait in wide pointer vtable
29+
y.foo();
30+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: constructing invalid value: wrong trait in wide pointer vtable: expected `Trait<for<'a> fn(&'a ())>`, but encountered `Trait<fn(&())>`
2+
--> tests/fail/validity/dyn-transmute-inner-binder.rs:LL:CC
3+
|
4+
LL | let y: &dyn Trait<for<'a> fn(&'a ())> = unsafe { std::mem::transmute(x) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: wrong trait in wide pointer vtable: expected `Trait<for<'a> fn(&'a ())>`, but encountered `Trait<fn(&())>`
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: BACKTRACE:
10+
= note: inside `main` at tests/fail/validity/dyn-transmute-inner-binder.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+

tests/pass/dyn-upcast.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn main() {
99
drop_principal();
1010
modulo_binder();
1111
modulo_assoc();
12+
bidirectional_subtyping();
1213
}
1314

1415
fn vtable_nop_cast() {
@@ -531,3 +532,32 @@ fn modulo_assoc() {
531532

532533
(&() as &dyn Trait as &dyn Middle<()>).say_hello(&0);
533534
}
535+
536+
fn bidirectional_subtyping() {
537+
// Test that transmuting between subtypes of dyn traits is fine, even in the
538+
// "wrong direction", i.e. going from a lower-ranked to a higher-ranked dyn trait.
539+
// Note that compared to the `dyn-transmute-inner-binder` test, the `for` is on the
540+
// *outside* here!
541+
542+
trait Trait<U: ?Sized> {}
543+
impl<T, U: ?Sized> Trait<U> for T {}
544+
545+
struct Wrapper<T: ?Sized>(T);
546+
547+
let x: &dyn Trait<fn(&'static ())> = &();
548+
let _y: &dyn for<'a> Trait<fn(&'a ())> = unsafe { std::mem::transmute(x) };
549+
550+
let x: &dyn for<'a> Trait<fn(&'a ())> = &();
551+
let _y: &dyn Trait<fn(&'static ())> = unsafe { std::mem::transmute(x) };
552+
553+
let x: &dyn Trait<dyn Trait<fn(&'static ())>> = &();
554+
let _y: &dyn for<'a> Trait<dyn Trait<fn(&'a ())>> = unsafe { std::mem::transmute(x) };
555+
556+
let x: &dyn for<'a> Trait<dyn Trait<fn(&'a ())>> = &();
557+
let _y: &dyn Trait<dyn Trait<fn(&'static ())>> = unsafe { std::mem::transmute(x) };
558+
559+
// This lowers to a ptr-to-ptr cast (which behaves like a transmute)
560+
// and not an unsizing coercion:
561+
let x: *const dyn for<'a> Trait<&'a ()> = &();
562+
let _y: *const Wrapper<dyn Trait<&'static ()>> = x as _;
563+
}

tests/pass/float.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(stmt_expr_attributes)]
2+
#![feature(float_erf)]
23
#![feature(float_gamma)]
34
#![feature(core_intrinsics)]
45
#![feature(f128)]
@@ -1076,6 +1077,11 @@ pub fn libm() {
10761077
let (val, sign) = (-0.5f64).ln_gamma();
10771078
assert_approx_eq!(val, (2.0 * f64::consts::PI.sqrt()).ln());
10781079
assert_eq!(sign, -1);
1080+
1081+
assert_approx_eq!(1.0f32.erf(), 0.84270079294971486934122063508260926f32);
1082+
assert_approx_eq!(1.0f64.erf(), 0.84270079294971486934122063508260926f64);
1083+
assert_approx_eq!(1.0f32.erfc(), 0.15729920705028513065877936491739074f32);
1084+
assert_approx_eq!(1.0f64.erfc(), 0.15729920705028513065877936491739074f64);
10791085
}
10801086

10811087
fn test_fast() {

0 commit comments

Comments
 (0)