Skip to content

Commit 3d159a6

Browse files
committed
Auto merge of #1048 - Aaron1011:panic-rustup, r=RalfJung
Rustup for panic changes This gets Miri working again, but doesn't actually implement unwinding
2 parents 69415b4 + c6d3179 commit 3d159a6

File tree

8 files changed

+24
-10
lines changed

8 files changed

+24
-10
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ Several `-Z` flags are relevant for Miri:
172172
sets this flag per default.
173173
* `-Zmir-emit-retag` controls whether `Retag` statements are emitted. Miri
174174
enables this per default because it is needed for validation.
175+
* `-Zno-codegen` makes rustc skip generating LLVM IR for MIR (though it still
176+
writes out empty object files). This is needed to prevent rustc from trying
177+
to codegen certain panic-related intrinsics, which will not work with a
178+
`libpanic_unwind` compiled in `cfg(miri)` mode. It also speeds up
179+
building our custom libstd.
175180

176181
Moreover, Miri recognizes some environment variables:
177182

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
56237d75b4271a8a2e0f47d86ea76ebf6d966152
1+
a333eed7fc0c903df9d6befcfb40af02148bf255

src/eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) {
213213
};
214214
e.print_backtrace();
215215
if let Some(frame) = ecx.stack().last() {
216-
let block = &frame.body.basic_blocks()[frame.block];
216+
let block = &frame.body.basic_blocks()[frame.block.unwrap()];
217217
let span = if frame.stmt < block.statements.len() {
218218
block.statements[frame.stmt].source_info.span
219219
} else {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ pub use crate::eval::{eval_main, create_ecx, MiriConfig};
5151
/// Insert rustc arguments at the beginning of the argument list that Miri wants to be
5252
/// set per default, for maximal validation power.
5353
pub fn miri_default_args() -> &'static [&'static str] {
54-
&["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0", "--cfg=miri"]
54+
&["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0", "-Zno-codegen", "--cfg=miri"]
5555
}

src/machine.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
173173
args: &[OpTy<'tcx, Tag>],
174174
dest: Option<PlaceTy<'tcx, Tag>>,
175175
ret: Option<mir::BasicBlock>,
176+
_unwind: Option<mir::BasicBlock>,
176177
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
177178
ecx.find_fn(instance, args, dest, ret)
178179
}
@@ -194,8 +195,14 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
194195
span: Span,
195196
instance: ty::Instance<'tcx>,
196197
args: &[OpTy<'tcx, Tag>],
197-
dest: PlaceTy<'tcx, Tag>,
198+
dest: Option<PlaceTy<'tcx, Tag>>,
199+
_ret: Option<mir::BasicBlock>,
200+
_unwind: Option<mir::BasicBlock>
198201
) -> InterpResult<'tcx> {
202+
let dest = match dest {
203+
Some(dest) => dest,
204+
None => throw_ub!(Unreachable)
205+
};
199206
ecx.call_intrinsic(span, instance, args, dest)
200207
}
201208

@@ -353,13 +360,15 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
353360
fn stack_pop(
354361
ecx: &mut InterpCx<'mir, 'tcx, Self>,
355362
extra: stacked_borrows::CallId,
356-
) -> InterpResult<'tcx> {
357-
Ok(ecx
363+
_unwinding: bool
364+
) -> InterpResult<'tcx, StackPopInfo> {
365+
ecx
358366
.memory
359367
.extra
360368
.stacked_borrows
361369
.borrow_mut()
362-
.end_call(extra))
370+
.end_call(extra);
371+
Ok(StackPopInfo::Normal)
363372
}
364373

365374
#[inline(always)]

src/shims/foreign_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
335335
mir,
336336
Some(ret_place),
337337
// Directly return to caller.
338-
StackPopCleanup::Goto(Some(ret)),
338+
StackPopCleanup::Goto { ret: Some(ret), unwind: None },
339339
)?;
340340
let mut args = this.frame().body.args_iter();
341341

src/shims/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2222
dest: PlaceTy<'tcx, Tag>,
2323
) -> InterpResult<'tcx> {
2424
let this = self.eval_context_mut();
25-
if this.emulate_intrinsic(span, instance, args, dest)? {
25+
if this.emulate_intrinsic(span, instance, args, Some(dest))? {
2626
return Ok(());
2727
}
2828
let tcx = &{this.tcx.tcx};

src/shims/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2727
);
2828

2929
// First, run the common hooks also supported by CTFE.
30-
if this.hook_fn(instance, args, dest)? {
30+
if this.hook_panic_fn(instance, args, dest)? {
3131
this.goto_block(ret)?;
3232
return Ok(None);
3333
}

0 commit comments

Comments
 (0)