Skip to content

Commit 94c8e17

Browse files
committed
add test checking that we do run MIR validation
1 parent c305e20 commit 94c8e17

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/panic/mir-validation.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Ensure that the MIR validator runs on Miri's input.
2+
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
3+
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
4+
//@normalize-stderr-test: "\n[ =]*note:.*" -> ""
5+
#![feature(custom_mir, core_intrinsics)]
6+
use core::intrinsics::mir::*;
7+
8+
#[custom_mir(dialect = "runtime", phase = "optimized")]
9+
pub fn main() {
10+
mir! {
11+
let x: i32;
12+
let tuple: (*mut i32,);
13+
{
14+
tuple.0 = core::ptr::addr_of_mut!(x);
15+
// Deref at the wrong place!
16+
*(tuple.0) = 1;
17+
Return()
18+
}
19+
}
20+
}

tests/panic/mir-validation.stderr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
thread 'rustc' panicked at compiler/rustc_const_eval/src/transform/validate.rs:LL:CC:
2+
broken MIR in Item(DefId(0:4 ~ mir_validation[fad2]::main)) (after phase change to runtime-optimized) at bb0[1]:
3+
(*(_2.0: *mut i32)), has deref at the wrong place
4+
stack backtrace:
5+
[... omitted 1 frame ...]
6+
7+
error: the compiler unexpectedly panicked. this is a bug.
8+
9+
10+
11+
12+
query stack during panic:
13+
#0 [optimized_mir] optimizing MIR for `main`
14+
end of query stack
15+
16+
Miri caused an ICE during evaluation. Here's the interpreter backtrace at the time of the panic:
17+
--> RUSTLIB/core/src/ops/function.rs:LL:CC
18+
|
19+
LL | extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
|
22+

0 commit comments

Comments
 (0)