Skip to content

Commit d568423

Browse files
committedMay 4, 2024
Auto merge of #124716 - matthiaskrgr:rollup-ni58ie1, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #122441 (Improve several `Read` implementations) - #124584 (Various improvements to entrypoint code) - #124699 (Use `unchecked_sub` in `split_at`) - #124715 (interpret, miri: uniform treatments of intrinsics/functions with and without return block) r? `@ghost` `@rustbot` modify labels: rollup
·
1.89.01.80.0
2 parents 1a851da + 743be1e commit d568423

File tree

34 files changed

+279
-293
lines changed

34 files changed

+279
-293
lines changed
 

‎compiler/rustc_ast/src/entry.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,35 @@ use rustc_span::Symbol;
44

55
#[derive(Debug)]
66
pub enum EntryPointType {
7+
/// This function is not an entrypoint.
78
None,
9+
/// This is a function called `main` at the root level.
10+
/// ```
11+
/// fn main() {}
12+
/// ```
813
MainNamed,
14+
/// This is a function with the `#[rustc_main]` attribute.
15+
/// Used by the testing harness to create the test entrypoint.
16+
/// ```ignore (clashes with test entrypoint)
17+
/// #[rustc_main]
18+
/// fn main() {}
19+
/// ```
920
RustcMainAttr,
21+
/// This is a function with the `#[start]` attribute.
22+
/// ```ignore (clashes with test entrypoint)
23+
/// #[start]
24+
/// fn main() {}
25+
/// ```
1026
Start,
11-
OtherMain, // Not an entry point, but some other function named main
27+
/// This function is **not** an entrypoint but simply named `main` (not at the root).
28+
/// This is only used for diagnostics.
29+
/// ```
30+
/// #[allow(dead_code)]
31+
/// mod meow {
32+
/// fn main() {}
33+
/// }
34+
/// ```
35+
OtherMain,
1236
}
1337

1438
pub fn entry_point_type(

‎compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fn generate_test_harness(
266266
///
267267
/// By default this expands to
268268
///
269-
/// ```ignore UNSOLVED (I think I still need guidance for this one. Is it correct? Do we try to make it run? How do we nicely fill it out?)
269+
/// ```ignore (messes with test internals)
270270
/// #[rustc_main]
271271
/// pub fn main() {
272272
/// extern crate test;

‎compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -467,19 +467,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
467467
let intrinsic_name = ecx.tcx.item_name(instance.def_id());
468468

469469
// CTFE-specific intrinsics.
470-
let Some(ret) = target else {
471-
// Handle diverging intrinsics. We can't handle any of them (that are not already
472-
// handled above), but check if there is a fallback body.
473-
if ecx.tcx.intrinsic(instance.def_id()).unwrap().must_be_overridden {
474-
throw_unsup_format!(
475-
"intrinsic `{intrinsic_name}` is not supported at compile-time"
476-
);
477-
}
478-
return Ok(Some(ty::Instance {
479-
def: ty::InstanceDef::Item(instance.def_id()),
480-
args: instance.args,
481-
}));
482-
};
483470
match intrinsic_name {
484471
sym::ptr_guaranteed_cmp => {
485472
let a = ecx.read_scalar(&args[0])?;
@@ -559,7 +546,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
559546
}
560547
}
561548

562-
ecx.go_to_block(ret);
549+
// Intrinsic is done, jump to next block.
550+
ecx.return_to_block(target)?;
563551
Ok(None)
564552
}
565553

‎compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
113113
) -> InterpResult<'tcx, bool> {
114114
let instance_args = instance.args;
115115
let intrinsic_name = self.tcx.item_name(instance.def_id());
116-
let Some(ret) = ret else {
117-
// We don't support any intrinsic without return place.
118-
return Ok(false);
119-
};
120116

121117
match intrinsic_name {
122118
sym::caller_location => {
@@ -376,7 +372,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
376372
};
377373

378374
M::panic_nounwind(self, &msg)?;
379-
// Skip the `go_to_block` at the end.
375+
// Skip the `return_to_block` at the end (we panicked, we do not return).
380376
return Ok(true);
381377
}
382378
}
@@ -437,11 +433,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
437433
self.write_scalar(Scalar::from_target_usize(align.bytes(), self), dest)?;
438434
}
439435

436+
// Unsupported intrinsic: skip the return_to_block below.
440437
_ => return Ok(false),
441438
}
442439

443440
trace!("{:?}", self.dump_place(&dest.clone().into()));
444-
self.go_to_block(ret);
441+
self.return_to_block(ret)?;
445442
Ok(true)
446443
}
447444

‎compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ passes_attr_crate_level =
4949
passes_attr_only_in_functions =
5050
`{$attr}` attribute can only be used on functions
5151
52-
passes_attr_only_on_main =
53-
`{$attr}` attribute can only be used on `fn main()`
54-
55-
passes_attr_only_on_root_main =
56-
`{$attr}` attribute can only be used on root `fn main()`
57-
5852
passes_both_ffi_const_and_pure =
5953
`#[ffi_const]` function cannot be `#[ffi_pure]`
6054

‎compiler/rustc_passes/src/entry.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use crate::errors::{
1818
struct EntryContext<'tcx> {
1919
tcx: TyCtxt<'tcx>,
2020

21-
/// The function that has attribute named `main`.
22-
attr_main_fn: Option<(LocalDefId, Span)>,
21+
/// The function has the `#[rustc_main]` attribute.
22+
rustc_main_fn: Option<(LocalDefId, Span)>,
2323

24-
/// The function that has the attribute 'start' on it.
24+
/// The function that has the attribute `#[start]` on it.
2525
start_fn: Option<(LocalDefId, Span)>,
2626

2727
/// The functions that one might think are `main` but aren't, e.g.
@@ -42,10 +42,10 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
4242
}
4343

4444
let mut ctxt =
45-
EntryContext { tcx, attr_main_fn: None, start_fn: None, non_main_fns: Vec::new() };
45+
EntryContext { tcx, rustc_main_fn: None, start_fn: None, non_main_fns: Vec::new() };
4646

4747
for id in tcx.hir().items() {
48-
find_item(id, &mut ctxt);
48+
check_and_search_item(id, &mut ctxt);
4949
}
5050

5151
configure_main(tcx, &ctxt)
@@ -56,7 +56,16 @@ fn attr_span_by_symbol(ctxt: &EntryContext<'_>, id: ItemId, sym: Symbol) -> Opti
5656
attr::find_by_name(attrs, sym).map(|attr| attr.span)
5757
}
5858

59-
fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
59+
fn check_and_search_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
60+
if !matches!(ctxt.tcx.def_kind(id.owner_id), DefKind::Fn) {
61+
for attr in [sym::start, sym::rustc_main] {
62+
if let Some(span) = attr_span_by_symbol(ctxt, id, attr) {
63+
ctxt.tcx.dcx().emit_err(AttrOnlyInFunctions { span, attr });
64+
}
65+
}
66+
return;
67+
}
68+
6069
let at_root = ctxt.tcx.opt_local_parent(id.owner_id.def_id) == Some(CRATE_DEF_ID);
6170

6271
let attrs = ctxt.tcx.hir().attrs(id.hir_id());
@@ -65,26 +74,20 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
6574
at_root,
6675
ctxt.tcx.opt_item_name(id.owner_id.to_def_id()),
6776
);
77+
6878
match entry_point_type {
69-
EntryPointType::None => (),
70-
_ if !matches!(ctxt.tcx.def_kind(id.owner_id), DefKind::Fn) => {
71-
for attr in [sym::start, sym::rustc_main] {
72-
if let Some(span) = attr_span_by_symbol(ctxt, id, attr) {
73-
ctxt.tcx.dcx().emit_err(AttrOnlyInFunctions { span, attr });
74-
}
75-
}
76-
}
77-
EntryPointType::MainNamed => (),
79+
EntryPointType::None => {}
80+
EntryPointType::MainNamed => {}
7881
EntryPointType::OtherMain => {
7982
ctxt.non_main_fns.push(ctxt.tcx.def_span(id.owner_id));
8083
}
8184
EntryPointType::RustcMainAttr => {
82-
if ctxt.attr_main_fn.is_none() {
83-
ctxt.attr_main_fn = Some((id.owner_id.def_id, ctxt.tcx.def_span(id.owner_id)));
85+
if ctxt.rustc_main_fn.is_none() {
86+
ctxt.rustc_main_fn = Some((id.owner_id.def_id, ctxt.tcx.def_span(id.owner_id)));
8487
} else {
8588
ctxt.tcx.dcx().emit_err(MultipleRustcMain {
8689
span: ctxt.tcx.def_span(id.owner_id.to_def_id()),
87-
first: ctxt.attr_main_fn.unwrap().1,
90+
first: ctxt.rustc_main_fn.unwrap().1,
8891
additional: ctxt.tcx.def_span(id.owner_id.to_def_id()),
8992
});
9093
}
@@ -107,10 +110,11 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
107110
fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId, EntryFnType)> {
108111
if let Some((def_id, _)) = visitor.start_fn {
109112
Some((def_id.to_def_id(), EntryFnType::Start))
110-
} else if let Some((local_def_id, _)) = visitor.attr_main_fn {
113+
} else if let Some((local_def_id, _)) = visitor.rustc_main_fn {
111114
let def_id = local_def_id.to_def_id();
112115
Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx) }))
113116
} else {
117+
// The actual resolution of main happens in the resolver, this here
114118
if let Some(main_def) = tcx.resolutions(()).main_def
115119
&& let Some(def_id) = main_def.opt_fn_def_id()
116120
{

‎compiler/rustc_passes/src/errors.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,22 +1206,6 @@ pub struct NakedFunctionsMustUseNoreturn {
12061206
pub last_span: Span,
12071207
}
12081208

1209-
#[derive(Diagnostic)]
1210-
#[diag(passes_attr_only_on_main)]
1211-
pub struct AttrOnlyOnMain {
1212-
#[primary_span]
1213-
pub span: Span,
1214-
pub attr: Symbol,
1215-
}
1216-
1217-
#[derive(Diagnostic)]
1218-
#[diag(passes_attr_only_on_root_main)]
1219-
pub struct AttrOnlyOnRootMain {
1220-
#[primary_span]
1221-
pub span: Span,
1222-
pub attr: Symbol,
1223-
}
1224-
12251209
#[derive(Diagnostic)]
12261210
#[diag(passes_attr_only_in_functions)]
12271211
pub struct AttrOnlyInFunctions {

‎library/core/src/slice/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use crate::cmp::Ordering::{self, Equal, Greater, Less};
1010
use crate::fmt;
1111
use crate::hint;
12-
use crate::intrinsics::exact_div;
12+
use crate::intrinsics::{exact_div, unchecked_sub};
1313
use crate::mem::{self, SizedTypeProperties};
1414
use crate::num::NonZero;
1515
use crate::ops::{Bound, OneSidedRange, Range, RangeBounds};
@@ -1983,7 +1983,7 @@ impl<T> [T] {
19831983
);
19841984

19851985
// SAFETY: Caller has to check that `0 <= mid <= self.len()`
1986-
unsafe { (from_raw_parts(ptr, mid), from_raw_parts(ptr.add(mid), len - mid)) }
1986+
unsafe { (from_raw_parts(ptr, mid), from_raw_parts(ptr.add(mid), unchecked_sub(len, mid))) }
19871987
}
19881988

19891989
/// Divides one mutable slice into two at an index, without doing bounds checking.
@@ -2035,7 +2035,12 @@ impl<T> [T] {
20352035
//
20362036
// `[ptr; mid]` and `[mid; len]` are not overlapping, so returning a mutable reference
20372037
// is fine.
2038-
unsafe { (from_raw_parts_mut(ptr, mid), from_raw_parts_mut(ptr.add(mid), len - mid)) }
2038+
unsafe {
2039+
(
2040+
from_raw_parts_mut(ptr, mid),
2041+
from_raw_parts_mut(ptr.add(mid), unchecked_sub(len, mid)),
2042+
)
2043+
}
20392044
}
20402045

20412046
/// Divides one slice into two at an index, returning `None` if the slice is

‎library/std/src/io/cursor.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,27 @@ where
364364
self.pos += n as u64;
365365
Ok(())
366366
}
367+
368+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
369+
let content = self.remaining_slice();
370+
let len = content.len();
371+
buf.try_reserve(len)?;
372+
buf.extend_from_slice(content);
373+
self.pos += len as u64;
374+
375+
Ok(len)
376+
}
377+
378+
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
379+
let content =
380+
crate::str::from_utf8(self.remaining_slice()).map_err(|_| io::Error::INVALID_UTF8)?;
381+
let len = content.len();
382+
buf.try_reserve(len)?;
383+
buf.push_str(content);
384+
self.pos += len as u64;
385+
386+
Ok(len)
387+
}
367388
}
368389

369390
#[stable(feature = "rust1", since = "1.0.0")]

‎library/std/src/io/impls.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,9 @@ impl Read for &[u8] {
329329
#[inline]
330330
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
331331
let content = str::from_utf8(self).map_err(|_| io::Error::INVALID_UTF8)?;
332-
buf.push_str(content);
333332
let len = self.len();
333+
buf.try_reserve(len)?;
334+
buf.push_str(content);
334335
*self = &self[len..];
335336
Ok(len)
336337
}
@@ -473,14 +474,8 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
473474

474475
#[inline]
475476
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
476-
// We have to use a single contiguous slice because the `VecDequeue` might be split in the
477-
// middle of an UTF-8 character.
478-
let len = self.len();
479-
let content = self.make_contiguous();
480-
let string = str::from_utf8(content).map_err(|_| io::Error::INVALID_UTF8)?;
481-
buf.push_str(string);
482-
self.clear();
483-
Ok(len)
477+
// SAFETY: We only append to the buffer
478+
unsafe { io::append_to_string(buf, |buf| self.read_to_end(buf)) }
484479
}
485480
}
486481

‎library/std/src/io/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,10 @@ where
384384
{
385385
let mut g = Guard { len: buf.len(), buf: buf.as_mut_vec() };
386386
let ret = f(g.buf);
387-
if str::from_utf8(&g.buf[g.len..]).is_err() {
387+
388+
// SAFETY: the caller promises to only append data to `buf`
389+
let appended = g.buf.get_unchecked(g.len..);
390+
if str::from_utf8(appended).is_err() {
388391
ret.and_then(|_| Err(Error::INVALID_UTF8))
389392
} else {
390393
g.len = g.buf.len();

‎library/std/src/process.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,10 @@ impl Read for ChildStderr {
486486
fn is_read_vectored(&self) -> bool {
487487
self.inner.is_read_vectored()
488488
}
489+
490+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
491+
self.inner.read_to_end(buf)
492+
}
489493
}
490494

491495
impl AsInner<AnonPipe> for ChildStderr {

‎src/tools/miri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub use rustc_const_eval::interpret::*;
9595
#[doc(no_inline)]
9696
pub use rustc_const_eval::interpret::{self, AllocMap, PlaceTy, Provenance as _};
9797

98+
pub use crate::shims::EmulateItemResult;
9899
pub use crate::shims::env::{EnvVars, EvalContextExt as _};
99100
pub use crate::shims::foreign_items::{DynSym, EvalContextExt as _};
100101
pub use crate::shims::intrinsics::EvalContextExt as _;

‎src/tools/miri/src/shims/alloc.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_ast::expand::allocator::AllocatorKind;
44
use rustc_target::abi::{Align, Size};
55

66
use crate::*;
7-
use shims::foreign_items::EmulateForeignItemResult;
87

98
/// Check some basic requirements for this allocation request:
109
/// non-zero size, power-of-two alignment.
@@ -55,12 +54,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
5554
fn emulate_allocator(
5655
&mut self,
5756
default: impl FnOnce(&mut MiriInterpCx<'mir, 'tcx>) -> InterpResult<'tcx>,
58-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
57+
) -> InterpResult<'tcx, EmulateItemResult> {
5958
let this = self.eval_context_mut();
6059

6160
let Some(allocator_kind) = this.tcx.allocator_kind(()) else {
6261
// in real code, this symbol does not exist without an allocator
63-
return Ok(EmulateForeignItemResult::NotSupported);
62+
return Ok(EmulateItemResult::NotSupported);
6463
};
6564

6665
match allocator_kind {
@@ -70,11 +69,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
7069
// and not execute any Miri shim. Somewhat unintuitively doing so is done
7170
// by returning `NotSupported`, which triggers the `lookup_exported_symbol`
7271
// fallback case in `emulate_foreign_item`.
73-
return Ok(EmulateForeignItemResult::NotSupported);
72+
return Ok(EmulateItemResult::NotSupported);
7473
}
7574
AllocatorKind::Default => {
7675
default(this)?;
77-
Ok(EmulateForeignItemResult::NeedsJumping)
76+
Ok(EmulateItemResult::NeedsJumping)
7877
}
7978
}
8079
}

‎src/tools/miri/src/shims/foreign_items.rs

Lines changed: 69 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ impl DynSym {
2828
}
2929
}
3030

31-
/// Returned by `emulate_foreign_item_inner`.
32-
pub enum EmulateForeignItemResult {
33-
/// The caller is expected to jump to the return block.
34-
NeedsJumping,
35-
/// Jumping has already been taken care of.
36-
AlreadyJumped,
37-
/// The item is not supported.
38-
NotSupported,
39-
}
40-
4131
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
4232
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4333
/// Emulates calling a foreign item, failing if the item is not supported.
@@ -58,84 +48,47 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
5848
let this = self.eval_context_mut();
5949
let tcx = this.tcx.tcx;
6050

61-
// First: functions that diverge.
62-
let ret = match ret {
63-
None =>
64-
match link_name.as_str() {
65-
"miri_start_unwind" => {
66-
// `check_shim` happens inside `handle_miri_start_unwind`.
67-
this.handle_miri_start_unwind(abi, link_name, args, unwind)?;
68-
return Ok(None);
69-
}
70-
// This matches calls to the foreign item `panic_impl`.
71-
// The implementation is provided by the function with the `#[panic_handler]` attribute.
72-
"panic_impl" => {
73-
// We don't use `check_shim` here because we are just forwarding to the lang
74-
// item. Argument count checking will be performed when the returned `Body` is
75-
// called.
76-
this.check_abi_and_shim_symbol_clash(abi, Abi::Rust, link_name)?;
77-
let panic_impl_id = tcx.lang_items().panic_impl().unwrap();
78-
let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id);
79-
return Ok(Some((
80-
this.load_mir(panic_impl_instance.def, None)?,
81-
panic_impl_instance,
82-
)));
83-
}
84-
"__rust_alloc_error_handler" => {
85-
// Forward to the right symbol that implements this function.
86-
let Some(handler_kind) = this.tcx.alloc_error_handler_kind(()) else {
87-
// in real code, this symbol does not exist without an allocator
88-
throw_unsup_format!(
89-
"`__rust_alloc_error_handler` cannot be called when no alloc error handler is set"
90-
);
91-
};
92-
let name = alloc_error_handler_name(handler_kind);
93-
let handler = this
94-
.lookup_exported_symbol(Symbol::intern(name))?
95-
.expect("missing alloc error handler symbol");
96-
return Ok(Some(handler));
97-
}
98-
#[rustfmt::skip]
99-
| "exit"
100-
| "ExitProcess"
101-
=> {
102-
let exp_abi = if link_name.as_str() == "exit" {
103-
Abi::C { unwind: false }
104-
} else {
105-
Abi::System { unwind: false }
106-
};
107-
let [code] = this.check_shim(abi, exp_abi, link_name, args)?;
108-
// it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway
109-
let code = this.read_scalar(code)?.to_i32()?;
110-
throw_machine_stop!(TerminationInfo::Exit { code: code.into(), leak_check: false });
111-
}
112-
"abort" => {
113-
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
114-
throw_machine_stop!(TerminationInfo::Abort(
115-
"the program aborted execution".to_owned()
116-
))
117-
}
118-
_ => {
119-
if let Some(body) = this.lookup_exported_symbol(link_name)? {
120-
return Ok(Some(body));
121-
}
122-
this.handle_unsupported(format!(
123-
"can't call (diverging) foreign function: {link_name}"
124-
))?;
125-
return Ok(None);
126-
}
127-
},
128-
Some(p) => p,
129-
};
51+
// Some shims forward to other MIR bodies.
52+
match link_name.as_str() {
53+
// This matches calls to the foreign item `panic_impl`.
54+
// The implementation is provided by the function with the `#[panic_handler]` attribute.
55+
"panic_impl" => {
56+
// We don't use `check_shim` here because we are just forwarding to the lang
57+
// item. Argument count checking will be performed when the returned `Body` is
58+
// called.
59+
this.check_abi_and_shim_symbol_clash(abi, Abi::Rust, link_name)?;
60+
let panic_impl_id = tcx.lang_items().panic_impl().unwrap();
61+
let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id);
62+
return Ok(Some((
63+
this.load_mir(panic_impl_instance.def, None)?,
64+
panic_impl_instance,
65+
)));
66+
}
67+
"__rust_alloc_error_handler" => {
68+
// Forward to the right symbol that implements this function.
69+
let Some(handler_kind) = this.tcx.alloc_error_handler_kind(()) else {
70+
// in real code, this symbol does not exist without an allocator
71+
throw_unsup_format!(
72+
"`__rust_alloc_error_handler` cannot be called when no alloc error handler is set"
73+
);
74+
};
75+
let name = alloc_error_handler_name(handler_kind);
76+
let handler = this
77+
.lookup_exported_symbol(Symbol::intern(name))?
78+
.expect("missing alloc error handler symbol");
79+
return Ok(Some(handler));
80+
}
81+
_ => {}
82+
}
13083

131-
// Second: functions that return immediately.
132-
match this.emulate_foreign_item_inner(link_name, abi, args, dest)? {
133-
EmulateForeignItemResult::NeedsJumping => {
84+
// The rest either implements the logic, or falls back to `lookup_exported_symbol`.
85+
match this.emulate_foreign_item_inner(link_name, abi, args, dest, unwind)? {
86+
EmulateItemResult::NeedsJumping => {
13487
trace!("{:?}", this.dump_place(&dest.clone().into()));
135-
this.go_to_block(ret);
88+
this.return_to_block(ret)?;
13689
}
137-
EmulateForeignItemResult::AlreadyJumped => (),
138-
EmulateForeignItemResult::NotSupported => {
90+
EmulateItemResult::AlreadyJumped => (),
91+
EmulateItemResult::NotSupported => {
13992
if let Some(body) = this.lookup_exported_symbol(link_name)? {
14093
return Ok(Some(body));
14194
}
@@ -243,7 +196,8 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
243196
abi: Abi,
244197
args: &[OpTy<'tcx, Provenance>],
245198
dest: &MPlaceTy<'tcx, Provenance>,
246-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
199+
unwind: mir::UnwindAction,
200+
) -> InterpResult<'tcx, EmulateItemResult> {
247201
let this = self.eval_context_mut();
248202

249203
// First deal with any external C functions in linked .so file.
@@ -254,7 +208,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
254208
// by the specified `.so` file; we should continue and check if it corresponds to
255209
// a provided shim.
256210
if this.call_external_c_fct(link_name, dest, args)? {
257-
return Ok(EmulateForeignItemResult::NeedsJumping);
211+
return Ok(EmulateItemResult::NeedsJumping);
258212
}
259213
}
260214

@@ -298,6 +252,11 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
298252
// shim, add it to the corresponding submodule.
299253
match link_name.as_str() {
300254
// Miri-specific extern functions
255+
"miri_start_unwind" => {
256+
// `check_shim` happens inside `handle_miri_start_unwind`.
257+
this.handle_miri_start_unwind(abi, link_name, args, unwind)?;
258+
return Ok(EmulateItemResult::AlreadyJumped);
259+
}
301260
"miri_run_provenance_gc" => {
302261
let [] = this.check_shim(abi, Abi::Rust, link_name, args)?;
303262
this.run_provenance_gc();
@@ -362,29 +321,24 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
362321
// Return value: 0 on success, otherwise the size it would have needed.
363322
this.write_int(if success { 0 } else { needed_size }, dest)?;
364323
}
365-
366324
// Obtains the size of a Miri backtrace. See the README for details.
367325
"miri_backtrace_size" => {
368326
this.handle_miri_backtrace_size(abi, link_name, args, dest)?;
369327
}
370-
371328
// Obtains a Miri backtrace. See the README for details.
372329
"miri_get_backtrace" => {
373330
// `check_shim` happens inside `handle_miri_get_backtrace`.
374331
this.handle_miri_get_backtrace(abi, link_name, args, dest)?;
375332
}
376-
377333
// Resolves a Miri backtrace frame. See the README for details.
378334
"miri_resolve_frame" => {
379335
// `check_shim` happens inside `handle_miri_resolve_frame`.
380336
this.handle_miri_resolve_frame(abi, link_name, args, dest)?;
381337
}
382-
383338
// Writes the function and file names of a Miri backtrace frame into a user provided buffer. See the README for details.
384339
"miri_resolve_frame_names" => {
385340
this.handle_miri_resolve_frame_names(abi, link_name, args)?;
386341
}
387-
388342
// Writes some bytes to the interpreter's stdout/stderr. See the
389343
// README for details.
390344
"miri_write_to_stdout" | "miri_write_to_stderr" => {
@@ -398,7 +352,6 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
398352
_ => unreachable!(),
399353
};
400354
}
401-
402355
// Promises that a pointer has a given symbolic alignment.
403356
"miri_promise_symbolic_alignment" => {
404357
use rustc_target::abi::AlignFromBytesError;
@@ -442,6 +395,25 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
442395
}
443396
}
444397

398+
// Aborting the process.
399+
"exit" | "ExitProcess" => {
400+
let exp_abi = if link_name.as_str() == "exit" {
401+
Abi::C { unwind: false }
402+
} else {
403+
Abi::System { unwind: false }
404+
};
405+
let [code] = this.check_shim(abi, exp_abi, link_name, args)?;
406+
// it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway
407+
let code = this.read_scalar(code)?.to_i32()?;
408+
throw_machine_stop!(TerminationInfo::Exit { code: code.into(), leak_check: false });
409+
}
410+
"abort" => {
411+
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
412+
throw_machine_stop!(TerminationInfo::Abort(
413+
"the program aborted execution".to_owned()
414+
))
415+
}
416+
445417
// Standard C allocation
446418
"malloc" => {
447419
let [size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
@@ -504,7 +476,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
504476
"__rust_alloc" => return this.emulate_allocator(default),
505477
"miri_alloc" => {
506478
default(this)?;
507-
return Ok(EmulateForeignItemResult::NeedsJumping);
479+
return Ok(EmulateItemResult::NeedsJumping);
508480
}
509481
_ => unreachable!(),
510482
}
@@ -564,7 +536,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
564536
}
565537
"miri_dealloc" => {
566538
default(this)?;
567-
return Ok(EmulateForeignItemResult::NeedsJumping);
539+
return Ok(EmulateItemResult::NeedsJumping);
568540
}
569541
_ => unreachable!(),
570542
}
@@ -966,11 +938,11 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
966938
shims::windows::foreign_items::EvalContextExt::emulate_foreign_item_inner(
967939
this, link_name, abi, args, dest,
968940
),
969-
_ => Ok(EmulateForeignItemResult::NotSupported),
941+
_ => Ok(EmulateItemResult::NotSupported),
970942
},
971943
};
972944
// We only fall through to here if we did *not* hit the `_` arm above,
973945
// i.e., if we actually emulated the function with one of the shims.
974-
Ok(EmulateForeignItemResult::NeedsJumping)
946+
Ok(EmulateItemResult::NeedsJumping)
975947
}
976948
}

‎src/tools/miri/src/shims/intrinsics/atomic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
2020
intrinsic_name: &str,
2121
args: &[OpTy<'tcx, Provenance>],
2222
dest: &MPlaceTy<'tcx, Provenance>,
23-
) -> InterpResult<'tcx, bool> {
23+
) -> InterpResult<'tcx, EmulateItemResult> {
2424
let this = self.eval_context_mut();
2525

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

117-
_ => return Ok(false),
117+
_ => return Ok(EmulateItemResult::NotSupported),
118118
}
119-
Ok(true)
119+
Ok(EmulateItemResult::NeedsJumping)
120120
}
121121
}
122122

‎src/tools/miri/src/shims/intrinsics/mod.rs

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_middle::{
1010
mir,
1111
ty::{self, FloatTy},
1212
};
13-
use rustc_target::abi::Size;
1413
use rustc_span::{sym, Symbol};
14+
use rustc_target::abi::Size;
1515

1616
use crate::*;
1717
use atomic::EvalContextExt as _;
@@ -37,51 +37,38 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
3737
let intrinsic_name = this.tcx.item_name(instance.def_id());
3838
let intrinsic_name = intrinsic_name.as_str();
3939

40-
// Handle intrinsics without return place.
41-
match intrinsic_name {
42-
"abort" => {
43-
throw_machine_stop!(TerminationInfo::Abort(
44-
"the program aborted execution".to_owned()
45-
))
46-
}
47-
_ => {}
48-
}
49-
50-
// All remaining supported intrinsics have a return place.
51-
let ret = match ret {
52-
// FIXME: add fallback body support once we actually have a diverging intrinsic with a fallback body
53-
None => throw_unsup_format!("unimplemented (diverging) intrinsic: `{intrinsic_name}`"),
54-
Some(p) => p,
55-
};
56-
57-
// Some intrinsics are special and need the "ret".
58-
match intrinsic_name {
59-
"catch_unwind" => {
60-
this.handle_catch_unwind(args, dest, ret)?;
61-
return Ok(None);
62-
}
63-
_ => {}
64-
}
65-
66-
// The rest jumps to `ret` immediately.
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}`")
40+
match this.emulate_intrinsic_by_name(intrinsic_name, instance.args, args, dest, ret)? {
41+
EmulateItemResult::NotSupported => {
42+
// We haven't handled the intrinsic, let's see if we can use a fallback body.
43+
if this.tcx.intrinsic(instance.def_id()).unwrap().must_be_overridden {
44+
throw_unsup_format!("unimplemented intrinsic: `{intrinsic_name}`")
45+
}
46+
let intrinsic_fallback_checks_ub = Symbol::intern("intrinsic_fallback_checks_ub");
47+
if this
48+
.tcx
49+
.get_attrs_by_path(
50+
instance.def_id(),
51+
&[sym::miri, intrinsic_fallback_checks_ub],
52+
)
53+
.next()
54+
.is_none()
55+
{
56+
throw_unsup_format!(
57+
"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"
58+
);
59+
}
60+
Ok(Some(ty::Instance {
61+
def: ty::InstanceDef::Item(instance.def_id()),
62+
args: instance.args,
63+
}))
7164
}
72-
let intrinsic_fallback_checks_ub = Symbol::intern("intrinsic_fallback_checks_ub");
73-
if this.tcx.get_attrs_by_path(instance.def_id(), &[sym::miri, intrinsic_fallback_checks_ub]).next().is_none() {
74-
throw_unsup_format!("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");
65+
EmulateItemResult::NeedsJumping => {
66+
trace!("{:?}", this.dump_place(&dest.clone().into()));
67+
this.return_to_block(ret)?;
68+
Ok(None)
7569
}
76-
return Ok(Some(ty::Instance {
77-
def: ty::InstanceDef::Item(instance.def_id()),
78-
args: instance.args,
79-
}))
70+
EmulateItemResult::AlreadyJumped => Ok(None),
8071
}
81-
82-
trace!("{:?}", this.dump_place(&dest.clone().into()));
83-
this.go_to_block(ret);
84-
Ok(None)
8572
}
8673

8774
/// Emulates a Miri-supported intrinsic (not supported by the core engine).
@@ -92,7 +79,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9279
generic_args: ty::GenericArgsRef<'tcx>,
9380
args: &[OpTy<'tcx, Provenance>],
9481
dest: &MPlaceTy<'tcx, Provenance>,
95-
) -> InterpResult<'tcx, bool> {
82+
ret: Option<mir::BasicBlock>,
83+
) -> InterpResult<'tcx, EmulateItemResult> {
9684
let this = self.eval_context_mut();
9785

9886
if let Some(name) = intrinsic_name.strip_prefix("atomic_") {
@@ -103,6 +91,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
10391
}
10492

10593
match intrinsic_name {
94+
"abort" => {
95+
throw_machine_stop!(TerminationInfo::Abort(
96+
"the program aborted execution".to_owned()
97+
));
98+
}
99+
"catch_unwind" => {
100+
this.handle_catch_unwind(args, dest, ret)?;
101+
// THis pushed a stack frame, don't jump to `ret`.
102+
return Ok(EmulateItemResult::AlreadyJumped);
103+
}
104+
106105
// Raw memory accesses
107106
"volatile_load" => {
108107
let [place] = check_arg_count(args)?;
@@ -426,9 +425,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
426425
throw_machine_stop!(TerminationInfo::Abort(format!("trace/breakpoint trap")))
427426
}
428427

429-
_ => return Ok(false),
428+
_ => return Ok(EmulateItemResult::NotSupported),
430429
}
431430

432-
Ok(true)
431+
Ok(EmulateItemResult::NeedsJumping)
433432
}
434433
}

‎src/tools/miri/src/shims/intrinsics/simd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
2323
generic_args: ty::GenericArgsRef<'tcx>,
2424
args: &[OpTy<'tcx, Provenance>],
2525
dest: &MPlaceTy<'tcx, Provenance>,
26-
) -> InterpResult<'tcx, bool> {
26+
) -> InterpResult<'tcx, EmulateItemResult> {
2727
let this = self.eval_context_mut();
2828
match intrinsic_name {
2929
#[rustfmt::skip]
@@ -744,9 +744,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
744744
}
745745
}
746746

747-
_ => return Ok(false),
747+
_ => return Ok(EmulateItemResult::NotSupported),
748748
}
749-
Ok(true)
749+
Ok(EmulateItemResult::NeedsJumping)
750750
}
751751

752752
fn fminmax_op(

‎src/tools/miri/src/shims/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ pub mod os_str;
1616
pub mod panic;
1717
pub mod time;
1818
pub mod tls;
19+
20+
/// What needs to be done after emulating an item (a shim or an intrinsic) is done.
21+
pub enum EmulateItemResult {
22+
/// The caller is expected to jump to the return block.
23+
NeedsJumping,
24+
/// Jumping has already been taken care of.
25+
AlreadyJumped,
26+
/// The item is not supported.
27+
NotSupported,
28+
}

‎src/tools/miri/src/shims/panic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct CatchUnwindData<'tcx> {
3030
/// The return place from the original call to `try`.
3131
dest: MPlaceTy<'tcx, Provenance>,
3232
/// The return block from the original call to `try`.
33-
ret: mir::BasicBlock,
33+
ret: Option<mir::BasicBlock>,
3434
}
3535

3636
impl VisitProvenance for CatchUnwindData<'_> {
@@ -73,7 +73,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
7373
&mut self,
7474
args: &[OpTy<'tcx, Provenance>],
7575
dest: &MPlaceTy<'tcx, Provenance>,
76-
ret: mir::BasicBlock,
76+
ret: Option<mir::BasicBlock>,
7777
) -> InterpResult<'tcx> {
7878
let this = self.eval_context_mut();
7979

@@ -103,7 +103,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
103103
&[data.into()],
104104
None,
105105
// Directly return to caller.
106-
StackPopCleanup::Goto { ret: Some(ret), unwind: mir::UnwindAction::Continue },
106+
StackPopCleanup::Goto { ret, unwind: mir::UnwindAction::Continue },
107107
)?;
108108

109109
// We ourselves will return `0`, eventually (will be overwritten if we catch a panic).
@@ -155,7 +155,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
155155
None,
156156
// Directly return to caller of `try`.
157157
StackPopCleanup::Goto {
158-
ret: Some(catch_unwind.ret),
158+
ret: catch_unwind.ret,
159159
unwind: mir::UnwindAction::Continue,
160160
},
161161
)?;

‎src/tools/miri/src/shims/unix/foreign_items.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_target::spec::abi::Abi;
99
use crate::shims::alloc::EvalContextExt as _;
1010
use crate::shims::unix::*;
1111
use crate::*;
12-
use shims::foreign_items::EmulateForeignItemResult;
1312

1413
use shims::unix::freebsd::foreign_items as freebsd;
1514
use shims::unix::linux::foreign_items as linux;
@@ -43,7 +42,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4342
abi: Abi,
4443
args: &[OpTy<'tcx, Provenance>],
4544
dest: &MPlaceTy<'tcx, Provenance>,
46-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
45+
) -> InterpResult<'tcx, EmulateItemResult> {
4746
let this = self.eval_context_mut();
4847

4948
// See `fn emulate_foreign_item_inner` in `shims/foreign_items.rs` for the general pattern.
@@ -750,11 +749,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
750749
"freebsd" => freebsd::EvalContextExt::emulate_foreign_item_inner(this, link_name, abi, args, dest),
751750
"linux" => linux::EvalContextExt::emulate_foreign_item_inner(this, link_name, abi, args, dest),
752751
"macos" => macos::EvalContextExt::emulate_foreign_item_inner(this, link_name, abi, args, dest),
753-
_ => Ok(EmulateForeignItemResult::NotSupported),
752+
_ => Ok(EmulateItemResult::NotSupported),
754753
};
755754
}
756755
};
757756

758-
Ok(EmulateForeignItemResult::NeedsJumping)
757+
Ok(EmulateItemResult::NeedsJumping)
759758
}
760759
}

‎src/tools/miri/src/shims/unix/freebsd/foreign_items.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use rustc_target::spec::abi::Abi;
33

44
use crate::shims::unix::*;
55
use crate::*;
6-
use shims::foreign_items::EmulateForeignItemResult;
76

87
pub fn is_dyn_sym(_name: &str) -> bool {
98
false
@@ -17,7 +16,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1716
abi: Abi,
1817
args: &[OpTy<'tcx, Provenance>],
1918
dest: &MPlaceTy<'tcx, Provenance>,
20-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
19+
) -> InterpResult<'tcx, EmulateItemResult> {
2120
let this = self.eval_context_mut();
2221
match link_name.as_str() {
2322
// Threading
@@ -97,8 +96,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9796
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
9897
}
9998

100-
_ => return Ok(EmulateForeignItemResult::NotSupported),
99+
_ => return Ok(EmulateItemResult::NotSupported),
101100
}
102-
Ok(EmulateForeignItemResult::NeedsJumping)
101+
Ok(EmulateItemResult::NeedsJumping)
103102
}
104103
}

‎src/tools/miri/src/shims/unix/linux/foreign_items.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::machine::SIGRTMAX;
55
use crate::machine::SIGRTMIN;
66
use crate::shims::unix::*;
77
use crate::*;
8-
use shims::foreign_items::EmulateForeignItemResult;
98
use shims::unix::linux::epoll::EvalContextExt as _;
109
use shims::unix::linux::eventfd::EvalContextExt as _;
1110
use shims::unix::linux::mem::EvalContextExt as _;
@@ -23,7 +22,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
2322
abi: Abi,
2423
args: &[OpTy<'tcx, Provenance>],
2524
dest: &MPlaceTy<'tcx, Provenance>,
26-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
25+
) -> InterpResult<'tcx, EmulateItemResult> {
2726
let this = self.eval_context_mut();
2827

2928
// See `fn emulate_foreign_item_inner` in `shims/foreign_items.rs` for the general pattern.
@@ -156,7 +155,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
156155
}
157156
id => {
158157
this.handle_unsupported(format!("can't execute syscall with ID {id}"))?;
159-
return Ok(EmulateForeignItemResult::AlreadyJumped);
158+
return Ok(EmulateItemResult::AlreadyJumped);
160159
}
161160
}
162161
}
@@ -204,10 +203,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
204203
this.write_null(dest)?;
205204
}
206205

207-
_ => return Ok(EmulateForeignItemResult::NotSupported),
206+
_ => return Ok(EmulateItemResult::NotSupported),
208207
};
209208

210-
Ok(EmulateForeignItemResult::NeedsJumping)
209+
Ok(EmulateItemResult::NeedsJumping)
211210
}
212211
}
213212

‎src/tools/miri/src/shims/unix/macos/foreign_items.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use rustc_target::spec::abi::Abi;
33

44
use crate::shims::unix::*;
55
use crate::*;
6-
use shims::foreign_items::EmulateForeignItemResult;
76

87
pub fn is_dyn_sym(_name: &str) -> bool {
98
false
@@ -17,7 +16,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1716
abi: Abi,
1817
args: &[OpTy<'tcx, Provenance>],
1918
dest: &MPlaceTy<'tcx, Provenance>,
20-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
19+
) -> InterpResult<'tcx, EmulateItemResult> {
2120
let this = self.eval_context_mut();
2221

2322
// See `fn emulate_foreign_item_inner` in `shims/foreign_items.rs` for the general pattern.
@@ -175,9 +174,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
175174
this.write_scalar(res, dest)?;
176175
}
177176

178-
_ => return Ok(EmulateForeignItemResult::NotSupported),
177+
_ => return Ok(EmulateItemResult::NotSupported),
179178
};
180179

181-
Ok(EmulateForeignItemResult::NeedsJumping)
180+
Ok(EmulateItemResult::NeedsJumping)
182181
}
183182
}

‎src/tools/miri/src/shims/windows/foreign_items.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::shims::alloc::EvalContextExt as _;
1212
use crate::shims::os_str::bytes_to_os_str;
1313
use crate::shims::windows::*;
1414
use crate::*;
15-
use shims::foreign_items::EmulateForeignItemResult;
1615
use shims::windows::handle::{Handle, PseudoHandle};
1716

1817
fn is_dyn_sym(name: &str) -> bool {
@@ -86,7 +85,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8685
abi: Abi,
8786
args: &[OpTy<'tcx, Provenance>],
8887
dest: &MPlaceTy<'tcx, Provenance>,
89-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
88+
) -> InterpResult<'tcx, EmulateItemResult> {
9089
let this = self.eval_context_mut();
9190

9291
// See `fn emulate_foreign_item_inner` in `shims/foreign_items.rs` for the general pattern.
@@ -721,9 +720,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
721720
this.write_null(dest)?;
722721
}
723722

724-
_ => return Ok(EmulateForeignItemResult::NotSupported),
723+
_ => return Ok(EmulateItemResult::NotSupported),
725724
}
726725

727-
Ok(EmulateForeignItemResult::NeedsJumping)
726+
Ok(EmulateItemResult::NeedsJumping)
728727
}
729728
}

‎src/tools/miri/src/shims/x86/aesni.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_span::Symbol;
44
use rustc_target::spec::abi::Abi;
55

66
use crate::*;
7-
use shims::foreign_items::EmulateForeignItemResult;
87

98
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
109
pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
@@ -16,7 +15,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
1615
abi: Abi,
1716
args: &[OpTy<'tcx, Provenance>],
1817
dest: &MPlaceTy<'tcx, Provenance>,
19-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
18+
) -> InterpResult<'tcx, EmulateItemResult> {
2019
let this = self.eval_context_mut();
2120
this.expect_target_feature_for_intrinsic(link_name, "aes")?;
2221
// Prefix should have already been checked.
@@ -126,9 +125,9 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
126125
}
127126
// TODO: Implement the `llvm.x86.aesni.aeskeygenassist` when possible
128127
// with an external crate.
129-
_ => return Ok(EmulateForeignItemResult::NotSupported),
128+
_ => return Ok(EmulateItemResult::NotSupported),
130129
}
131-
Ok(EmulateForeignItemResult::NeedsJumping)
130+
Ok(EmulateItemResult::NeedsJumping)
132131
}
133132
}
134133

‎src/tools/miri/src/shims/x86/avx.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use super::{
1111
FloatBinOp, FloatUnaryOp,
1212
};
1313
use crate::*;
14-
use shims::foreign_items::EmulateForeignItemResult;
1514

1615
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
1716
pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
@@ -23,7 +22,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
2322
abi: Abi,
2423
args: &[OpTy<'tcx, Provenance>],
2524
dest: &MPlaceTy<'tcx, Provenance>,
26-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
25+
) -> InterpResult<'tcx, EmulateItemResult> {
2726
let this = self.eval_context_mut();
2827
this.expect_target_feature_for_intrinsic(link_name, "avx")?;
2928
// Prefix should have already been checked.
@@ -343,8 +342,8 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
343342

344343
this.write_scalar(Scalar::from_i32(res.into()), dest)?;
345344
}
346-
_ => return Ok(EmulateForeignItemResult::NotSupported),
345+
_ => return Ok(EmulateItemResult::NotSupported),
347346
}
348-
Ok(EmulateForeignItemResult::NeedsJumping)
347+
Ok(EmulateItemResult::NeedsJumping)
349348
}
350349
}

‎src/tools/miri/src/shims/x86/avx2.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use super::{
99
packuswb, pmulhrsw, psign, shift_simd_by_scalar, shift_simd_by_simd, ShiftOp,
1010
};
1111
use crate::*;
12-
use shims::foreign_items::EmulateForeignItemResult;
1312

1413
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
1514
pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
@@ -21,7 +20,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
2120
abi: Abi,
2221
args: &[OpTy<'tcx, Provenance>],
2322
dest: &MPlaceTy<'tcx, Provenance>,
24-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
23+
) -> InterpResult<'tcx, EmulateItemResult> {
2524
let this = self.eval_context_mut();
2625
this.expect_target_feature_for_intrinsic(link_name, "avx2")?;
2726
// Prefix should have already been checked.
@@ -437,8 +436,8 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
437436

438437
shift_simd_by_simd(this, left, right, which, dest)?;
439438
}
440-
_ => return Ok(EmulateForeignItemResult::NotSupported),
439+
_ => return Ok(EmulateItemResult::NotSupported),
441440
}
442-
Ok(EmulateForeignItemResult::NeedsJumping)
441+
Ok(EmulateItemResult::NeedsJumping)
443442
}
444443
}

‎src/tools/miri/src/shims/x86/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_target::spec::abi::Abi;
1010

1111
use crate::*;
1212
use helpers::bool_to_simd_element;
13-
use shims::foreign_items::EmulateForeignItemResult;
1413

1514
mod aesni;
1615
mod avx;
@@ -31,7 +30,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
3130
abi: Abi,
3231
args: &[OpTy<'tcx, Provenance>],
3332
dest: &MPlaceTy<'tcx, Provenance>,
34-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
33+
) -> InterpResult<'tcx, EmulateItemResult> {
3534
let this = self.eval_context_mut();
3635
// Prefix should have already been checked.
3736
let unprefixed_name = link_name.as_str().strip_prefix("llvm.x86.").unwrap();
@@ -43,7 +42,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
4342
// https://www.intel.com/content/www/us/en/docs/cpp-compiler/developer-guide-reference/2021-8/addcarry-u32-addcarry-u64.html
4443
"addcarry.32" | "addcarry.64" => {
4544
if unprefixed_name == "addcarry.64" && this.tcx.sess.target.arch != "x86_64" {
46-
return Ok(EmulateForeignItemResult::NotSupported);
45+
return Ok(EmulateItemResult::NotSupported);
4746
}
4847

4948
let [c_in, a, b] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?;
@@ -69,7 +68,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
6968
// https://www.intel.com/content/www/us/en/docs/cpp-compiler/developer-guide-reference/2021-8/subborrow-u32-subborrow-u64.html
7069
"subborrow.32" | "subborrow.64" => {
7170
if unprefixed_name == "subborrow.64" && this.tcx.sess.target.arch != "x86_64" {
72-
return Ok(EmulateForeignItemResult::NotSupported);
71+
return Ok(EmulateItemResult::NotSupported);
7372
}
7473

7574
let [b_in, a, b] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?;
@@ -143,9 +142,9 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
143142
);
144143
}
145144

146-
_ => return Ok(EmulateForeignItemResult::NotSupported),
145+
_ => return Ok(EmulateItemResult::NotSupported),
147146
}
148-
Ok(EmulateForeignItemResult::NeedsJumping)
147+
Ok(EmulateItemResult::NeedsJumping)
149148
}
150149
}
151150

‎src/tools/miri/src/shims/x86/sse.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use super::{
88
FloatUnaryOp,
99
};
1010
use crate::*;
11-
use shims::foreign_items::EmulateForeignItemResult;
1211

1312
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
1413
pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
@@ -20,7 +19,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
2019
abi: Abi,
2120
args: &[OpTy<'tcx, Provenance>],
2221
dest: &MPlaceTy<'tcx, Provenance>,
23-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
22+
) -> InterpResult<'tcx, EmulateItemResult> {
2423
let this = self.eval_context_mut();
2524
this.expect_target_feature_for_intrinsic(link_name, "sse")?;
2625
// Prefix should have already been checked.
@@ -211,8 +210,8 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
211210
this.copy_op(&this.project_index(&left, i)?, &this.project_index(&dest, i)?)?;
212211
}
213212
}
214-
_ => return Ok(EmulateForeignItemResult::NotSupported),
213+
_ => return Ok(EmulateItemResult::NotSupported),
215214
}
216-
Ok(EmulateForeignItemResult::NeedsJumping)
215+
Ok(EmulateItemResult::NeedsJumping)
217216
}
218217
}

‎src/tools/miri/src/shims/x86/sse2.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use super::{
77
packuswb, shift_simd_by_scalar, FloatBinOp, ShiftOp,
88
};
99
use crate::*;
10-
use shims::foreign_items::EmulateForeignItemResult;
1110

1211
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
1312
pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
@@ -19,7 +18,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
1918
abi: Abi,
2019
args: &[OpTy<'tcx, Provenance>],
2120
dest: &MPlaceTy<'tcx, Provenance>,
22-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
21+
) -> InterpResult<'tcx, EmulateItemResult> {
2322
let this = self.eval_context_mut();
2423
this.expect_target_feature_for_intrinsic(link_name, "sse2")?;
2524
// Prefix should have already been checked.
@@ -387,8 +386,8 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
387386
this.copy_op(&this.project_index(&left, i)?, &this.project_index(&dest, i)?)?;
388387
}
389388
}
390-
_ => return Ok(EmulateForeignItemResult::NotSupported),
389+
_ => return Ok(EmulateItemResult::NotSupported),
391390
}
392-
Ok(EmulateForeignItemResult::NeedsJumping)
391+
Ok(EmulateItemResult::NeedsJumping)
393392
}
394393
}

‎src/tools/miri/src/shims/x86/sse3.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_target::spec::abi::Abi;
44

55
use super::horizontal_bin_op;
66
use crate::*;
7-
use shims::foreign_items::EmulateForeignItemResult;
87

98
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
109
pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
@@ -16,7 +15,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
1615
abi: Abi,
1716
args: &[OpTy<'tcx, Provenance>],
1817
dest: &MPlaceTy<'tcx, Provenance>,
19-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
18+
) -> InterpResult<'tcx, EmulateItemResult> {
2019
let this = self.eval_context_mut();
2120
this.expect_target_feature_for_intrinsic(link_name, "sse3")?;
2221
// Prefix should have already been checked.
@@ -50,8 +49,8 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
5049

5150
this.mem_copy(src_ptr, dest.ptr(), dest.layout.size, /*nonoverlapping*/ true)?;
5251
}
53-
_ => return Ok(EmulateForeignItemResult::NotSupported),
52+
_ => return Ok(EmulateItemResult::NotSupported),
5453
}
55-
Ok(EmulateForeignItemResult::NeedsJumping)
54+
Ok(EmulateItemResult::NeedsJumping)
5655
}
5756
}

‎src/tools/miri/src/shims/x86/sse41.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use rustc_target::spec::abi::Abi;
33

44
use super::{conditional_dot_product, mpsadbw, packusdw, round_all, round_first, test_bits_masked};
55
use crate::*;
6-
use shims::foreign_items::EmulateForeignItemResult;
76

87
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
98
pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
@@ -15,7 +14,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
1514
abi: Abi,
1615
args: &[OpTy<'tcx, Provenance>],
1716
dest: &MPlaceTy<'tcx, Provenance>,
18-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
17+
) -> InterpResult<'tcx, EmulateItemResult> {
1918
let this = self.eval_context_mut();
2019
this.expect_target_feature_for_intrinsic(link_name, "sse4.1")?;
2120
// Prefix should have already been checked.
@@ -175,8 +174,8 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
175174

176175
this.write_scalar(Scalar::from_i32(res.into()), dest)?;
177176
}
178-
_ => return Ok(EmulateForeignItemResult::NotSupported),
177+
_ => return Ok(EmulateItemResult::NotSupported),
179178
}
180-
Ok(EmulateForeignItemResult::NeedsJumping)
179+
Ok(EmulateItemResult::NeedsJumping)
181180
}
182181
}

‎src/tools/miri/src/shims/x86/ssse3.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_target::spec::abi::Abi;
44

55
use super::{horizontal_bin_op, int_abs, pmulhrsw, psign};
66
use crate::*;
7-
use shims::foreign_items::EmulateForeignItemResult;
87

98
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
109
pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
@@ -16,7 +15,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
1615
abi: Abi,
1716
args: &[OpTy<'tcx, Provenance>],
1817
dest: &MPlaceTy<'tcx, Provenance>,
19-
) -> InterpResult<'tcx, EmulateForeignItemResult> {
18+
) -> InterpResult<'tcx, EmulateItemResult> {
2019
let this = self.eval_context_mut();
2120
this.expect_target_feature_for_intrinsic(link_name, "ssse3")?;
2221
// Prefix should have already been checked.
@@ -136,8 +135,8 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
136135

137136
psign(this, left, right, dest)?;
138137
}
139-
_ => return Ok(EmulateForeignItemResult::NotSupported),
138+
_ => return Ok(EmulateItemResult::NotSupported),
140139
}
141-
Ok(EmulateForeignItemResult::NeedsJumping)
140+
Ok(EmulateItemResult::NeedsJumping)
142141
}
143142
}

0 commit comments

Comments
 (0)
Please sign in to comment.