Skip to content

Commit

Permalink
Auto merge of #1221 - RalfJung:rustup, r=RalfJung
Browse files Browse the repository at this point in the history
Rustup
  • Loading branch information
bors committed Mar 11, 2020
2 parents 704228d + 76ee8ff commit 4fc8542
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
303d8aff6092709edd4dbd35b1c88e9aa40bf6d8
c20d7eecbc0928b57da8fe30b2ef8528e2bdd5be
22 changes: 12 additions & 10 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ extern crate log;
extern crate log_settings;
extern crate miri;
extern crate rustc;
extern crate rustc_codegen_utils;
extern crate rustc_driver;
extern crate rustc_errors;
extern crate rustc_hir;
extern crate rustc_interface;
extern crate rustc_metadata;
extern crate rustc_span;
extern crate rustc_session;

use std::convert::TryFrom;
use std::env;
use std::str::FromStr;

use hex::FromHexError;

use rustc_session::CtfeBacktrace;
use rustc_driver::Compilation;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_interface::{interface, Queries};
use rustc::ty::TyCtxt;

struct MiriCompilerCalls {
miri_config: miri::MiriConfig,
Expand All @@ -35,10 +34,10 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
compiler: &interface::Compiler,
queries: &'tcx Queries<'tcx>,
) -> Compilation {
init_late_loggers();
compiler.session().abort_if_errors();

queries.global_ctxt().unwrap().peek_mut().enter(|tcx| {
init_late_loggers(tcx);
let (entry_def_id, _) = tcx.entry_fn(LOCAL_CRATE).expect("no main function found!");
let mut config = self.miri_config.clone();

Expand Down Expand Up @@ -72,7 +71,7 @@ fn init_early_loggers() {
}
}

fn init_late_loggers() {
fn init_late_loggers(tcx: TyCtxt<'_>) {
// We initialize loggers right before we start evaluation. We overwrite the `RUSTC_LOG`
// env var if it is not set, control it based on `MIRI_LOG`.
if let Ok(var) = env::var("MIRI_LOG") {
Expand All @@ -96,10 +95,13 @@ fn init_late_loggers() {

// If `MIRI_BACKTRACE` is set and `RUSTC_CTFE_BACKTRACE` is not, set `RUSTC_CTFE_BACKTRACE`.
// Do this late, so we ideally only apply this to Miri's errors.
if let Ok(var) = env::var("MIRI_BACKTRACE") {
if env::var("RUSTC_CTFE_BACKTRACE") == Err(env::VarError::NotPresent) {
env::set_var("RUSTC_CTFE_BACKTRACE", &var);
}
if let Ok(val) = env::var("MIRI_BACKTRACE") {
let ctfe_backtrace = match &*val {
"immediate" => CtfeBacktrace::Immediate,
"0" => CtfeBacktrace::Disabled,
_ => CtfeBacktrace::Capture,
};
*tcx.sess.ctfe_backtrace.borrow_mut() = ctfe_backtrace;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
#[inline(always)]
fn assert_panic(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
span: Span,
msg: &mir::AssertMessage<'tcx>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
ecx.assert_panic(span, msg, unwind)
ecx.assert_panic(msg, unwind)
}

#[inline(always)]
Expand Down
10 changes: 3 additions & 7 deletions src/shims/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use rustc::mir;
use rustc::ty::{self, layout::LayoutOf};
use rustc_target::spec::PanicStrategy;
use rustc_span::source_map::Span;

use crate::*;

Expand Down Expand Up @@ -176,7 +175,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx

fn assert_panic(
&mut self,
span: Span,
msg: &mir::AssertMessage<'tcx>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
Expand All @@ -187,19 +185,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
BoundsCheck { ref index, ref len } => {
// Forward to `panic_bounds_check` lang item.

// First arg: Caller location.
let location = this.alloc_caller_location_for_span(span);
// Second arg: index.
// First arg: index.
let index = this.read_scalar(this.eval_operand(index, None)?)?;
// Third arg: len.
// Second arg: len.
let len = this.read_scalar(this.eval_operand(len, None)?)?;

// Call the lang item.
let panic_bounds_check = this.tcx.lang_items().panic_bounds_check_fn().unwrap();
let panic_bounds_check = ty::Instance::mono(this.tcx.tcx, panic_bounds_check);
this.call_function(
panic_bounds_check,
&[location.ptr.into(), index.into(), len.into()],
&[index.into(), len.into()],
None,
StackPopCleanup::Goto { ret: None, unwind },
)?;
Expand Down

0 comments on commit 4fc8542

Please sign in to comment.