Skip to content

Commit 1183c87

Browse files
committed
Tweak the lint and add a Miri test
1 parent 8a834d7 commit 1183c87

3 files changed

Lines changed: 64 additions & 8 deletions

File tree

src/tools/miri/src/eval.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,16 @@ pub fn create_ecx<'tcx>(
289289
MiriMachine::new(config, layout_cx, genmc_ctx),
290290
);
291291

292-
// Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
293-
let sentinel =
294-
helpers::try_resolve_path(tcx, &["core", "ascii", "escape_default"], Namespace::ValueNS);
295-
if !matches!(sentinel, Some(s) if tcx.is_mir_available(s.def.def_id())) {
296-
tcx.dcx().fatal(
297-
"the current sysroot was built without `-Zalways-encode-mir`, or libcore seems missing.\n\
298-
Note that directly invoking the `miri` binary is not supported; please use `cargo miri` instead."
299-
);
292+
if !rustc_hir::find_attr!(tcx, crate, NoCore(..)) {
293+
// Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
294+
let sentinel =
295+
helpers::try_resolve_path(tcx, &["core", "ascii", "escape_default"], Namespace::ValueNS);
296+
if !matches!(sentinel, Some(s) if tcx.is_mir_available(s.def.def_id())) {
297+
tcx.dcx().fatal(
298+
"the current sysroot was built without `-Zalways-encode-mir`, or libcore seems missing.\n\
299+
Note that directly invoking the `miri` binary is not supported; please use `cargo miri` instead."
300+
);
301+
}
300302
}
301303

302304
// Compute argc and argv from `config.args`.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Test that when we call a function with #[rustc_panic_entrypoint], we encounter an abort and do
2+
// not actually execute the function. Immediate-aborting panics are implemented by a rewrite of such
3+
// functions, so this tests that the rewrite works with Miri.
4+
5+
//@compile-flags: -Cpanic=immediate-abort -Zunstable-options --target=x86_64-unknown-none
6+
7+
#![no_std]
8+
#![no_core]
9+
#![no_main]
10+
#![feature(rustc_attrs, no_core, lang_items, intrinsics)]
11+
#![allow(internal_features)]
12+
13+
#[lang = "pointee_sized"]
14+
#[diagnostic::on_unimplemented(
15+
message = "values of type `{Self}` may or may not have a size",
16+
label = "may or may not have a known size"
17+
)]
18+
pub trait PointeeSized {}
19+
20+
#[lang = "meta_sized"]
21+
#[diagnostic::on_unimplemented(
22+
message = "the size for values of type `{Self}` cannot be known",
23+
label = "doesn't have a known size"
24+
)]
25+
pub trait MetaSized: PointeeSized {}
26+
27+
#[lang = "sized"]
28+
#[diagnostic::on_unimplemented(
29+
message = "the size for values of type `{Self}` cannot be known at compilation time",
30+
label = "doesn't have a size known at compile-time"
31+
)]
32+
pub trait Sized: MetaSized {}
33+
34+
#[rustc_nounwind]
35+
#[rustc_intrinsic]
36+
#[lang = "abort_intrinsic"]
37+
fn abort() -> !;
38+
39+
#[no_mangle]
40+
fn miri_start(_argc: isize, _argv: *const *const u8) -> isize {
41+
panic_entrypoint(); //~ ERROR: abnormal termination: the program aborted execution
42+
0
43+
}
44+
45+
#[rustc_panic_entrypoint]
46+
fn panic_entrypoint() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: abnormal termination: the program aborted execution
2+
--> tests/fail/immediate-abort.rs:LL:CC
3+
|
4+
LL | panic_entrypoint();
5+
| ^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)