Skip to content

Commit bde979f

Browse files
committed
Auto merge of #3561 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 9a7c124 + 1aa686f commit bde979f

File tree

9 files changed

+74
-38
lines changed

9 files changed

+74
-38
lines changed

bench-cargo-miri/mse/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ static EXPECTED: &[u8] = &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44
static PCM: &[i16] = &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 1, 0, 1, 0, 0, -2, 0, -2, 0, -2, 0, -2, -2, -2, -3, -3, -3, -3, -4, -2, -5, -2, -5, -2, -4, 0, -4, 0, -4, 0, -4, 1, -4, 1, -4, 2, -4, 2, -4, 2, -4, 2, -4, 2, -3, 1, -4, 0, -4, 0, -5, 0, -5, 0, -5, 0, -4, 2, -4, 3, -4, 4, -3, 5, -2, 5, -3, 6, -3, 6, -3, 5, -3, 5, -2, 4, -2, 3, -5, 0, -6, 0, -3, -2, -4, -4, -9, -5, -9, -4, -4, -2, -4, -2, -4, 0, -2, 1, 1, 1, 4, 2, 8, 2, 12, 1, 13, 0, 12, 0, 11, 0, 8, -2, 7, 0, 7, -3, 11, -8, 15, -9, 17, -6, 17, -5, 13, -3, 7, 0, 3, 0, -2, 0, -4, 0, -4, -2, -6, 0, -14, -2, -17, -4, -8, 0, -7, 5, -17, 7, -18, 10, -7, 18, -2, 25, -3, 27, 0, 31, 4, 34, 4, 34, 8, 36, 8, 37, 2, 36, 4, 34, 8, 28, 3, 15, 0, 11, 0, 12, -5, 8, -4, 10, 0, 23, -4, 31, -8, 30, -2, 30, 0, 26, -6, 22, -6, 20, -12, 15, -19, 10, -10, 13, -14, 6, -43, -13, -43, -16, -9, -12, -10, -29, -42, -40, -37, -28, -5, -21, 1, -24, -8, -20, 4, -18, 26, -24, 44, -26, 66, -30, 86, -37, 88, -41, 72, -46, 50, -31, 28, 23, 14, 64, 16, 51, 26, 32, 34, 39, 42, 48, 35, 58, 0, 72, -36, 69, -59, 58, -98, 54, -124, 36, -103, 12, -110, 5, -173, -19, -146, -59, -4, -42, 51, 1, -23, -6, -30, -6, 45, 46, 47, 70, 6, 55, 19, 60, 38, 62, 42, 47, 61, 46, 40, 42, -19, 22, -34, 6, -35, -50, -61, -141, -37, -171, 17, -163, 26, -180, 46, -154, 80, -63, 48, -4, 18, 20, 50, 47, 58, 53, 44, 61, 57, 85, 37, 80, 0, 86, -8, 106, -95, 49, -213, -8, -131, 47, 49, 63, 40, -39, -69, -74, -37, -20, 63, -12, 58, -14, -12, 25, -31, 41, 11, 45, 76, 47, 167, 5, 261, -37, 277, -83, 183, -172, 35, -122, -79, 138, -70, 266, 69, 124, 228, 0, 391, -29, 594, -84, 702, -78, 627, -8, 551, -13, 509, 13, 372, 120, 352, 125, 622, 127, 691, 223, 362, 126, 386, -33, 915, 198, 958, 457, 456, 298, 500, 233, 1027, 469, 1096, 426, 918, 160, 1067, 141, 1220, 189, 1245, 164, 1375, 297, 1378, 503, 1299, 702, 1550, 929, 1799, 855, 1752, 547, 1830, 602, 1928, 832, 1736, 796, 1735, 933, 1961, 1385, 1935, 1562, 2105, 1485, 2716, 1449, 2948, 1305, 2768, 1205, 2716, 1346, 2531, 1450, 2470, 1653, 3117, 2111, 3370, 2176, 2696, 1947, 2925, 2305, 3846, 2658, 2425, 2184, -877, 1981, -2261, 2623, -1645, 2908, -1876, 2732, -2704, 2953, -2484, 3116, -2120, 2954, -2442, 3216, -2466, 3499, -2192, 3234, -2392, 3361, -2497, 3869, -2078, 3772, -1858, 3915, -2066, 4438, -2285, 2934, -2294, -280, -2066, -1762, -1992, -1412, -2298, -1535, -2399, -1789, -2223, -1419, -2244, -1334, -2092, -1476, -1777, -1396, -2014, -1571, -2199, -1574, -1843, -1167, -1910, -1446, -2007, -1818];
55

66
fn main() {
7-
#[cfg(increase_thread_usage)]
8-
let thread = std::thread::spawn(|| 4);
9-
107
for _ in 0..2 {
118
mse(PCM.len(), PCM, EXPECTED);
129
}

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d6d3b342e85272f5e75c0d7a1dd3a1d8becb40ac
1+
d7ea27808deb5e10a0f7384e339e4e6165e33398

src/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
387387
let main_ptr = ecx.fn_ptr(FnVal::Instance(entry_instance));
388388

389389
// Always using DEFAULT is okay since we don't support signals in Miri anyway.
390-
// (This means we are effectively ignoring `#[unix_sigpipe]`.)
390+
// (This means we are effectively ignoring `-Zon-broken-pipe`.)
391391
let sigpipe = rustc_session::config::sigpipe::DEFAULT;
392392

393393
ecx.call_function(

src/intrinsics/atomic.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ pub enum AtomicOp {
1414
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
1515
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1616
/// Calls the atomic intrinsic `intrinsic`; the `atomic_` prefix has already been removed.
17+
/// Returns `Ok(true)` if the intrinsic was handled.
1718
fn emulate_atomic_intrinsic(
1819
&mut self,
1920
intrinsic_name: &str,
2021
args: &[OpTy<'tcx, Provenance>],
2122
dest: &MPlaceTy<'tcx, Provenance>,
22-
) -> InterpResult<'tcx> {
23+
) -> InterpResult<'tcx, bool> {
2324
let this = self.eval_context_mut();
2425

2526
let intrinsic_structure: Vec<_> = intrinsic_name.split('_').collect();
@@ -113,9 +114,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
113114
this.atomic_rmw_op(args, dest, AtomicOp::Max, rw_ord(ord)?)?;
114115
}
115116

116-
_ => throw_unsup_format!("unimplemented intrinsic: `atomic_{intrinsic_name}`"),
117+
_ => return Ok(false),
117118
}
118-
Ok(())
119+
Ok(true)
119120
}
120121
}
121122

src/intrinsics/mod.rs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_middle::{
1010
mir,
1111
ty::{self, FloatTy},
1212
};
13+
use rustc_span::{sym, Symbol};
1314
use rustc_target::abi::Size;
1415

1516
use crate::*;
@@ -26,12 +27,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
2627
dest: &MPlaceTy<'tcx, Provenance>,
2728
ret: Option<mir::BasicBlock>,
2829
_unwind: mir::UnwindAction,
29-
) -> InterpResult<'tcx> {
30+
) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
3031
let this = self.eval_context_mut();
3132

3233
// See if the core engine can handle this intrinsic.
3334
if this.emulate_intrinsic(instance, args, dest, ret)? {
34-
return Ok(());
35+
return Ok(None);
3536
}
3637
let intrinsic_name = this.tcx.item_name(instance.def_id());
3738
let intrinsic_name = intrinsic_name.as_str();
@@ -48,32 +49,57 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4849

4950
// All remaining supported intrinsics have a return place.
5051
let ret = match ret {
52+
// FIXME: add fallback body support once we actually have a diverging intrinsic with a fallback body
5153
None => throw_unsup_format!("unimplemented (diverging) intrinsic: `{intrinsic_name}`"),
5254
Some(p) => p,
5355
};
5456

5557
// Some intrinsics are special and need the "ret".
5658
match intrinsic_name {
57-
"catch_unwind" => return this.handle_catch_unwind(args, dest, ret),
59+
"catch_unwind" => {
60+
this.handle_catch_unwind(args, dest, ret)?;
61+
return Ok(None);
62+
}
5863
_ => {}
5964
}
6065

6166
// The rest jumps to `ret` immediately.
62-
this.emulate_intrinsic_by_name(intrinsic_name, instance.args, args, dest)?;
67+
if !this.emulate_intrinsic_by_name(intrinsic_name, instance.args, args, dest)? {
68+
// We haven't handled the intrinsic, let's see if we can use a fallback body.
69+
if this.tcx.intrinsic(instance.def_id()).unwrap().must_be_overridden {
70+
throw_unsup_format!("unimplemented intrinsic: `{intrinsic_name}`")
71+
}
72+
let intrinsic_fallback_checks_ub = Symbol::intern("intrinsic_fallback_checks_ub");
73+
if this
74+
.tcx
75+
.get_attrs_by_path(instance.def_id(), &[sym::miri, intrinsic_fallback_checks_ub])
76+
.next()
77+
.is_none()
78+
{
79+
throw_unsup_format!(
80+
"miri can only use intrinsic fallback bodies that check UB. After verifying that `{intrinsic_name}` does so, add the `#[miri::intrinsic_fallback_checks_ub]` attribute to it; also ping @rust-lang/miri when you do that"
81+
);
82+
}
83+
return Ok(Some(ty::Instance {
84+
def: ty::InstanceDef::Item(instance.def_id()),
85+
args: instance.args,
86+
}));
87+
}
6388

6489
trace!("{:?}", this.dump_place(&dest.clone().into()));
6590
this.go_to_block(ret);
66-
Ok(())
91+
Ok(None)
6792
}
6893

6994
/// Emulates a Miri-supported intrinsic (not supported by the core engine).
95+
/// Returns `Ok(true)` if the intrinsic was handled.
7096
fn emulate_intrinsic_by_name(
7197
&mut self,
7298
intrinsic_name: &str,
7399
generic_args: ty::GenericArgsRef<'tcx>,
74100
args: &[OpTy<'tcx, Provenance>],
75101
dest: &MPlaceTy<'tcx, Provenance>,
76-
) -> InterpResult<'tcx> {
102+
) -> InterpResult<'tcx, bool> {
77103
let this = self.eval_context_mut();
78104

79105
if let Some(name) = intrinsic_name.strip_prefix("atomic_") {
@@ -84,24 +110,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
84110
}
85111

86112
match intrinsic_name {
87-
// Miri overwriting CTFE intrinsics.
88-
"ptr_guaranteed_cmp" => {
89-
let [left, right] = check_arg_count(args)?;
90-
let left = this.read_immediate(left)?;
91-
let right = this.read_immediate(right)?;
92-
let val = this.wrapping_binary_op(mir::BinOp::Eq, &left, &right)?;
93-
// We're type punning a bool as an u8 here.
94-
this.write_scalar(val.to_scalar(), dest)?;
95-
}
96-
"const_allocate" => {
97-
// For now, for compatibility with the run-time implementation of this, we just return null.
98-
// See <https://github.com/rust-lang/rust/issues/93935>.
99-
this.write_null(dest)?;
100-
}
101-
"const_deallocate" => {
102-
// complete NOP
103-
}
104-
105113
// Raw memory accesses
106114
"volatile_load" => {
107115
let [place] = check_arg_count(args)?;
@@ -425,9 +433,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
425433
throw_machine_stop!(TerminationInfo::Abort(format!("trace/breakpoint trap")))
426434
}
427435

428-
name => throw_unsup_format!("unimplemented intrinsic: `{name}`"),
436+
_ => return Ok(false),
429437
}
430438

431-
Ok(())
439+
Ok(true)
432440
}
433441
}

src/intrinsics/simd.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ pub(crate) enum MinMax {
1616
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
1717
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1818
/// Calls the simd intrinsic `intrinsic`; the `simd_` prefix has already been removed.
19+
/// Returns `Ok(true)` if the intrinsic was handled.
1920
fn emulate_simd_intrinsic(
2021
&mut self,
2122
intrinsic_name: &str,
2223
generic_args: ty::GenericArgsRef<'tcx>,
2324
args: &[OpTy<'tcx, Provenance>],
2425
dest: &MPlaceTy<'tcx, Provenance>,
25-
) -> InterpResult<'tcx> {
26+
) -> InterpResult<'tcx, bool> {
2627
let this = self.eval_context_mut();
2728
match intrinsic_name {
2829
#[rustfmt::skip]
@@ -743,9 +744,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
743744
}
744745
}
745746

746-
name => throw_unsup_format!("unimplemented intrinsic: `simd_{name}`"),
747+
_ => return Ok(false),
747748
}
748-
Ok(())
749+
Ok(true)
749750
}
750751

751752
fn fminmax_op(

src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
986986
dest: &MPlaceTy<'tcx, Provenance>,
987987
ret: Option<mir::BasicBlock>,
988988
unwind: mir::UnwindAction,
989-
) -> InterpResult<'tcx> {
989+
) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
990990
ecx.call_intrinsic(instance, args, dest, ret, unwind)
991991
}
992992

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(rustc_attrs, effects)]
2+
3+
#[rustc_intrinsic]
4+
#[rustc_nounwind]
5+
#[rustc_do_not_const_check]
6+
#[inline]
7+
pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8 {
8+
(ptr == other) as u8
9+
}
10+
11+
fn main() {
12+
ptr_guaranteed_cmp::<()>(std::ptr::null(), std::ptr::null());
13+
//~^ ERROR: can only use intrinsic fallback bodies that check UB.
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: unsupported operation: miri can only use intrinsic fallback bodies that check UB. After verifying that `ptr_guaranteed_cmp` does so, add the `#[miri::intrinsic_fallback_checks_ub]` attribute to it; also ping @rust-lang/miri when you do that
2+
--> $DIR/intrinsic_fallback_checks_ub.rs:LL:CC
3+
|
4+
LL | ptr_guaranteed_cmp::<()>(std::ptr::null(), std::ptr::null());
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ miri can only use intrinsic fallback bodies that check UB. After verifying that `ptr_guaranteed_cmp` does so, add the `#[miri::intrinsic_fallback_checks_ub]` attribute to it; also ping @rust-lang/miri when you do that
6+
|
7+
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8+
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
9+
= note: BACKTRACE:
10+
= note: inside `main` at $DIR/intrinsic_fallback_checks_ub.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+

0 commit comments

Comments
 (0)