Skip to content

Commit

Permalink
Merge pull request #1 from solson/fixup-function_pointers2
Browse files Browse the repository at this point in the history
Fixup function_pointers2
  • Loading branch information
oli-obk authored Jun 13, 2016
2 parents 384623d + 024b3d2 commit 4ae77b7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 88 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 17 additions & 19 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(rustc_private, custom_attribute)]
#![allow(unused_attributes)]
#![feature(rustc_private)]

extern crate getopts;
extern crate miri;
Expand Down Expand Up @@ -66,21 +65,22 @@ fn interpret_start_points<'a, 'tcx>(
ecx.push_stack_frame(tcx.map.local_def_id(id), mir.span, CachedMir::Ref(mir), substs, return_ptr);

loop {
match (step(&mut ecx), return_ptr) {
(Ok(true), _) => {},
(Ok(false), Some(ptr)) => if log_enabled!(::log::LogLevel::Debug) {
ecx.memory().dump(ptr.alloc_id);
match step(&mut ecx) {
Ok(true) => {}
Ok(false) => {
match return_ptr {
Some(ptr) => if log_enabled!(::log::LogLevel::Debug) {
ecx.memory().dump(ptr.alloc_id);
},
None => warn!("diverging function returned"),
}
break;
},
(Ok(false), None) => {
warn!("diverging function returned");
break;
},
}
// FIXME: diverging functions can end up here in some future miri
(Err(e), _) => {
Err(e) => {
report(tcx, &ecx, e);
break;
},
}
}
}
}
Expand All @@ -90,11 +90,11 @@ fn interpret_start_points<'a, 'tcx>(

fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
let frame = ecx.stack().last().expect("stackframe was empty");
let block = frame.mir.basic_block_data(frame.next_block);
let block = &frame.mir.basic_blocks()[frame.next_block];
let span = if frame.stmt < block.statements.len() {
block.statements[frame.stmt].span
block.statements[frame.stmt].source_info.span
} else {
block.terminator().span
block.terminator().source_info.span
};
let mut err = tcx.sess.struct_span_err(span, &e.to_string());
for &Frame { def_id, substs, span, .. } in ecx.stack().iter().rev() {
Expand All @@ -105,22 +105,20 @@ fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
impl<'tcx> fmt::Display for Instance<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
ppaux::parameterized(f, self.1, self.0, ppaux::Ns::Value, &[],
|tcx| tcx.lookup_item_type(self.0).generics)
|tcx| Some(tcx.lookup_item_type(self.0).generics))
}
}
err.span_note(span, &format!("inside call to {}", Instance(def_id, substs)));
}
err.emit();
}

#[miri_run]
fn main() {
init_logger();
let args: Vec<String> = std::env::args().collect();
rustc_driver::run_compiler(&args, &mut MiriCompilerCalls);
}

#[miri_run]
fn init_logger() {
const NSPACES: usize = 40;
let format = |record: &log::LogRecord| {
Expand Down
54 changes: 44 additions & 10 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc::ty::layout::{self, Layout, Size};
use rustc::ty::subst::{self, Subst, Substs};
use rustc::ty::{self, Ty, TyCtxt, BareFnTy};
use rustc::util::nodemap::DefIdMap;
use rustc_data_structures::indexed_vec::Idx;
use std::cell::RefCell;
use std::ops::Deref;
use std::rc::Rc;
Expand Down Expand Up @@ -118,7 +119,7 @@ struct ConstantId<'tcx> {

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
enum ConstantKind {
Promoted(usize),
Promoted(mir::Promoted),
/// Statics, constants and associated constants
Global,
}
Expand Down Expand Up @@ -426,24 +427,38 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
assert_eq!(ptr.offset, 0);
let fn_ptr = self.memory.read_ptr(ptr)?;
let (def_id, substs) = self.memory.get_fn(fn_ptr.alloc_id)?;
self.eval_fn_call(def_id, substs, bare_fn_ty, return_ptr, args, terminator.span)?
self.eval_fn_call(def_id, substs, bare_fn_ty, return_ptr, args,
terminator.source_info.span)?
},
ty::TyFnDef(def_id, substs, fn_ty) => {
self.eval_fn_call(def_id, substs, fn_ty, return_ptr, args, terminator.span)?
self.eval_fn_call(def_id, substs, fn_ty, return_ptr, args,
terminator.source_info.span)?
}

_ => return Err(EvalError::Unimplemented(format!("can't handle callee of type {:?}", func_ty))),
}
}

Drop { ref value, target, .. } => {
let ptr = self.eval_lvalue(value)?.to_ptr();
let ty = self.lvalue_ty(value);
Drop { ref location, target, .. } => {
let ptr = self.eval_lvalue(location)?.to_ptr();
let ty = self.lvalue_ty(location);
self.drop(ptr, ty)?;
self.frame_mut().next_block = target;
}

Assert { ref cond, expected, ref msg, target, cleanup } => {
let actual_ptr = self.eval_operand(cond)?;
let actual = self.memory.read_bool(actual_ptr)?;
if actual == expected {
self.frame_mut().next_block = target;
} else {
panic!("unimplemented: jump to {:?} and print {:?}", cleanup, msg);
}
}

DropAndReplace { .. } => unimplemented!(),
Resume => unimplemented!(),
Unreachable => unimplemented!(),
}

Ok(())
Expand Down Expand Up @@ -867,6 +882,25 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
self.memory.write_primval(dest, val)?;
}

// FIXME(solson): Factor this out with BinaryOp.
CheckedBinaryOp(bin_op, ref left, ref right) => {
let left_ptr = self.eval_operand(left)?;
let left_ty = self.operand_ty(left);
let left_val = self.read_primval(left_ptr, left_ty)?;

let right_ptr = self.eval_operand(right)?;
let right_ty = self.operand_ty(right);
let right_val = self.read_primval(right_ptr, right_ty)?;

let val = primval::binary_op(bin_op, left_val, right_val)?;
self.memory.write_primval(dest, val)?;

// FIXME(solson): Find the result type size properly. Perhaps refactor out
// Projection calculations so we can do the equivalent of `dest.1` here.
let s = self.type_size(left_ty, self.substs());
self.memory.write_bool(dest.offset(s as isize), false)?;
}

UnaryOp(un_op, ref operand) => {
let ptr = self.eval_operand(operand)?;
let ty = self.operand_ty(operand);
Expand Down Expand Up @@ -1048,7 +1082,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
}

Slice { .. } => unimplemented!(),
InlineAsm { .. } => unimplemented!(),
}

Expand Down Expand Up @@ -1161,9 +1194,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let ptr = match *lvalue {
ReturnPointer => self.frame().return_ptr
.expect("ReturnPointer used in a function with no return value"),
Arg(i) => self.frame().locals[i as usize],
Var(i) => self.frame().locals[self.frame().var_offset + i as usize],
Temp(i) => self.frame().locals[self.frame().temp_offset + i as usize],
Arg(i) => self.frame().locals[i.index()],
Var(i) => self.frame().locals[self.frame().var_offset + i.index()],
Temp(i) => self.frame().locals[self.frame().temp_offset + i.index()],

Static(def_id) => {
let substs = self.tcx.mk_substs(subst::Substs::empty());
Expand Down Expand Up @@ -1248,6 +1281,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}

ConstantIndex { .. } => unimplemented!(),
Subslice { .. } => unimplemented!(),
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/interpreter/stepper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ impl<'ecx, 'a, 'tcx> Stepper<'ecx, 'a, 'tcx> {
let block = self.ecx.frame().next_block;
let stmt = self.ecx.frame().stmt;
let mir = self.ecx.mir();
let basic_block = mir.basic_block_data(block);
let basic_block = &mir.basic_blocks()[block];

if let Some(ref stmt) = basic_block.statements.get(stmt) {
let current_stack = self.ecx.stack.len();
ConstantExtractor {
span: stmt.span,
span: stmt.source_info.span,
substs: self.ecx.substs(),
def_id: self.ecx.frame().def_id,
ecx: self.ecx,
Expand All @@ -75,7 +75,7 @@ impl<'ecx, 'a, 'tcx> Stepper<'ecx, 'a, 'tcx> {
let terminator = basic_block.terminator();
let current_stack = self.ecx.stack.len();
ConstantExtractor {
span: terminator.span,
span: terminator.source_info.span,
substs: self.ecx.substs(),
def_id: self.ecx.frame().def_id,
ecx: self.ecx,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

// From rustc.
#[macro_use] extern crate rustc;
extern crate rustc_data_structures;
extern crate rustc_mir;
extern crate rustc_trans;
extern crate syntax;
Expand Down
1 change: 0 additions & 1 deletion tests/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ fn run_mode(mode: &'static str) {
fn compile_test() {
run_mode("compile-fail");
run_mode("run-pass");
run_mode("run-fail");
}
50 changes: 0 additions & 50 deletions tests/run-fail/inception.rs

This file was deleted.

0 comments on commit 4ae77b7

Please sign in to comment.