Skip to content

Commit 7949f68

Browse files
author
The Miri Conjob Bot
committed
Merge from rustc
2 parents 77a59d6 + 57a4c5d commit 7949f68

34 files changed

+252
-93
lines changed

src/machine.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -971,9 +971,22 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
971971
ecx.assert_panic(msg, unwind)
972972
}
973973

974-
#[inline(always)]
975-
fn abort(_ecx: &mut MiriInterpCx<'mir, 'tcx>, msg: String) -> InterpResult<'tcx, !> {
976-
throw_machine_stop!(TerminationInfo::Abort(msg))
974+
fn panic_nounwind(ecx: &mut InterpCx<'mir, 'tcx, Self>, msg: &str) -> InterpResult<'tcx> {
975+
ecx.start_panic_nounwind(msg)
976+
}
977+
978+
fn unwind_terminate(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
979+
// Call the lang item.
980+
let panic = ecx.tcx.lang_items().panic_cannot_unwind().unwrap();
981+
let panic = ty::Instance::mono(ecx.tcx.tcx, panic);
982+
ecx.call_function(
983+
panic,
984+
Abi::Rust,
985+
&[],
986+
None,
987+
StackPopCleanup::Goto { ret: None, unwind: mir::UnwindAction::Unreachable },
988+
)?;
989+
Ok(())
977990
}
978991

979992
#[inline(always)]

src/shims/intrinsics/mod.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
3434
if this.emulate_intrinsic(instance, args, dest, ret)? {
3535
return Ok(());
3636
}
37-
38-
// All remaining supported intrinsics have a return place.
3937
let intrinsic_name = this.tcx.item_name(instance.def_id());
4038
let intrinsic_name = intrinsic_name.as_str();
39+
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.
4151
let ret = match ret {
4252
None => throw_unsup_format!("unimplemented (diverging) intrinsic: `{intrinsic_name}`"),
4353
Some(p) => p,
@@ -393,7 +403,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
393403
"breakpoint" => {
394404
let [] = check_arg_count(args)?;
395405
// normally this would raise a SIGTRAP, which aborts if no debugger is connected
396-
throw_machine_stop!(TerminationInfo::Abort(format!("Trace/breakpoint trap")))
406+
throw_machine_stop!(TerminationInfo::Abort(format!("trace/breakpoint trap")))
397407
}
398408

399409
name => throw_unsup_format!("unimplemented intrinsic: `{name}`"),

src/shims/panic.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
188188
)
189189
}
190190

191+
/// Start a non-unwinding panic in the interpreter with the given message as payload.
192+
fn start_panic_nounwind(&mut self, msg: &str) -> InterpResult<'tcx> {
193+
let this = self.eval_context_mut();
194+
195+
// First arg: message.
196+
let msg = this.allocate_str(msg, MiriMemoryKind::Machine.into(), Mutability::Not)?;
197+
198+
// Call the lang item.
199+
let panic = this.tcx.lang_items().panic_nounwind().unwrap();
200+
let panic = ty::Instance::mono(this.tcx.tcx, panic);
201+
this.call_function(
202+
panic,
203+
Abi::Rust,
204+
&[msg.to_ref(this)],
205+
None,
206+
StackPopCleanup::Goto { ret: None, unwind: mir::UnwindAction::Unreachable },
207+
)
208+
}
209+
191210
fn assert_panic(
192211
&mut self,
193212
msg: &mir::AssertMessage<'tcx>,

tests/fail/breakpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
fn main() {
44
unsafe {
5-
core::intrinsics::breakpoint() //~ ERROR: Trace/breakpoint trap
5+
core::intrinsics::breakpoint() //~ ERROR: trace/breakpoint trap
66
};
77
}

tests/fail/breakpoint.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: abnormal termination: Trace/breakpoint trap
1+
error: abnormal termination: trace/breakpoint trap
22
--> $DIR/breakpoint.rs:LL:CC
33
|
44
LL | core::intrinsics::breakpoint()
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Trace/breakpoint trap
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trace/breakpoint trap
66
|
77
= note: inside `main` at $DIR/breakpoint.rs:LL:CC
88

tests/fail/function_calls/arg_inplace_mutate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ pub struct S(i32);
88
#[custom_mir(dialect = "runtime", phase = "optimized")]
99
fn main() {
1010
mir! {
11-
let unit: ();
11+
let _unit: ();
1212
{
1313
let non_copy = S(42);
1414
let ptr = std::ptr::addr_of_mut!(non_copy);
1515
// Inside `callee`, the first argument and `*ptr` are basically
1616
// aliasing places!
17-
Call(unit, after_call, callee(Move(*ptr), ptr))
17+
Call(_unit = callee(Move(*ptr), ptr), after_call)
1818
}
1919
after_call = {
2020
Return()

tests/fail/function_calls/arg_inplace_mutate.stack.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1010
--> $DIR/arg_inplace_mutate.rs:LL:CC
1111
|
1212
LL | / mir! {
13-
LL | | let unit: ();
13+
LL | | let _unit: ();
1414
LL | | {
1515
LL | | let non_copy = S(42);
1616
... |
@@ -27,8 +27,8 @@ LL | unsafe { ptr.write(S(0)) };
2727
note: inside `main`
2828
--> $DIR/arg_inplace_mutate.rs:LL:CC
2929
|
30-
LL | Call(unit, after_call, callee(Move(*ptr), ptr))
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
LL | Call(_unit = callee(Move(*ptr), ptr), after_call)
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)
3333

3434
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

tests/fail/function_calls/arg_inplace_mutate.tree.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ help: the accessed tag <TAG> was created here
1212
--> $DIR/arg_inplace_mutate.rs:LL:CC
1313
|
1414
LL | / mir! {
15-
LL | | let unit: ();
15+
LL | | let _unit: ();
1616
LL | | {
1717
LL | | let non_copy = S(42);
1818
... |
@@ -29,8 +29,8 @@ LL | unsafe { ptr.write(S(0)) };
2929
note: inside `main`
3030
--> $DIR/arg_inplace_mutate.rs:LL:CC
3131
|
32-
LL | Call(unit, after_call, callee(Move(*ptr), ptr))
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
LL | Call(_unit = callee(Move(*ptr), ptr), after_call)
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)
3535

3636
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

tests/fail/function_calls/arg_inplace_observe_after.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ pub struct S(i32);
66
#[custom_mir(dialect = "runtime", phase = "optimized")]
77
fn main() {
88
mir! {
9-
let unit: ();
9+
let _unit: ();
1010
let _observe: i32;
1111
{
1212
let non_copy = S(42);
1313
// This could change `non_copy` in-place
14-
Call(unit, after_call, change_arg(Move(non_copy)))
14+
Call(_unit = change_arg(Move(non_copy)), after_call)
1515
}
1616
after_call = {
1717
// So now we must not be allowed to observe non-copy again.

tests/fail/function_calls/arg_inplace_observe_during.none.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ LL | unsafe { ptr.read() };
1111
note: inside `main`
1212
--> $DIR/arg_inplace_observe_during.rs:LL:CC
1313
|
14-
LL | Call(unit, after_call, change_arg(Move(*ptr), ptr))
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call)
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616

1717
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1818

0 commit comments

Comments
 (0)