Skip to content

Commit 4ae77b7

Browse files
authored
Merge pull request #1 from solson/fixup-function_pointers2
Fixup function_pointers2
2 parents 384623d + 024b3d2 commit 4ae77b7

File tree

7 files changed

+70
-88
lines changed

7 files changed

+70
-88
lines changed

Cargo.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bin/miri.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![feature(rustc_private, custom_attribute)]
2-
#![allow(unused_attributes)]
1+
#![feature(rustc_private)]
32

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

6867
loop {
69-
match (step(&mut ecx), return_ptr) {
70-
(Ok(true), _) => {},
71-
(Ok(false), Some(ptr)) => if log_enabled!(::log::LogLevel::Debug) {
72-
ecx.memory().dump(ptr.alloc_id);
68+
match step(&mut ecx) {
69+
Ok(true) => {}
70+
Ok(false) => {
71+
match return_ptr {
72+
Some(ptr) => if log_enabled!(::log::LogLevel::Debug) {
73+
ecx.memory().dump(ptr.alloc_id);
74+
},
75+
None => warn!("diverging function returned"),
76+
}
7377
break;
74-
},
75-
(Ok(false), None) => {
76-
warn!("diverging function returned");
77-
break;
78-
},
78+
}
7979
// FIXME: diverging functions can end up here in some future miri
80-
(Err(e), _) => {
80+
Err(e) => {
8181
report(tcx, &ecx, e);
8282
break;
83-
},
83+
}
8484
}
8585
}
8686
}
@@ -90,11 +90,11 @@ fn interpret_start_points<'a, 'tcx>(
9090

9191
fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
9292
let frame = ecx.stack().last().expect("stackframe was empty");
93-
let block = frame.mir.basic_block_data(frame.next_block);
93+
let block = &frame.mir.basic_blocks()[frame.next_block];
9494
let span = if frame.stmt < block.statements.len() {
95-
block.statements[frame.stmt].span
95+
block.statements[frame.stmt].source_info.span
9696
} else {
97-
block.terminator().span
97+
block.terminator().source_info.span
9898
};
9999
let mut err = tcx.sess.struct_span_err(span, &e.to_string());
100100
for &Frame { def_id, substs, span, .. } in ecx.stack().iter().rev() {
@@ -105,22 +105,20 @@ fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
105105
impl<'tcx> fmt::Display for Instance<'tcx> {
106106
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
107107
ppaux::parameterized(f, self.1, self.0, ppaux::Ns::Value, &[],
108-
|tcx| tcx.lookup_item_type(self.0).generics)
108+
|tcx| Some(tcx.lookup_item_type(self.0).generics))
109109
}
110110
}
111111
err.span_note(span, &format!("inside call to {}", Instance(def_id, substs)));
112112
}
113113
err.emit();
114114
}
115115

116-
#[miri_run]
117116
fn main() {
118117
init_logger();
119118
let args: Vec<String> = std::env::args().collect();
120119
rustc_driver::run_compiler(&args, &mut MiriCompilerCalls);
121120
}
122121

123-
#[miri_run]
124122
fn init_logger() {
125123
const NSPACES: usize = 40;
126124
let format = |record: &log::LogRecord| {

src/interpreter/mod.rs

+44-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc::ty::layout::{self, Layout, Size};
88
use rustc::ty::subst::{self, Subst, Substs};
99
use rustc::ty::{self, Ty, TyCtxt, BareFnTy};
1010
use rustc::util::nodemap::DefIdMap;
11+
use rustc_data_structures::indexed_vec::Idx;
1112
use std::cell::RefCell;
1213
use std::ops::Deref;
1314
use std::rc::Rc;
@@ -118,7 +119,7 @@ struct ConstantId<'tcx> {
118119

119120
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
120121
enum ConstantKind {
121-
Promoted(usize),
122+
Promoted(mir::Promoted),
122123
/// Statics, constants and associated constants
123124
Global,
124125
}
@@ -426,24 +427,38 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
426427
assert_eq!(ptr.offset, 0);
427428
let fn_ptr = self.memory.read_ptr(ptr)?;
428429
let (def_id, substs) = self.memory.get_fn(fn_ptr.alloc_id)?;
429-
self.eval_fn_call(def_id, substs, bare_fn_ty, return_ptr, args, terminator.span)?
430+
self.eval_fn_call(def_id, substs, bare_fn_ty, return_ptr, args,
431+
terminator.source_info.span)?
430432
},
431433
ty::TyFnDef(def_id, substs, fn_ty) => {
432-
self.eval_fn_call(def_id, substs, fn_ty, return_ptr, args, terminator.span)?
434+
self.eval_fn_call(def_id, substs, fn_ty, return_ptr, args,
435+
terminator.source_info.span)?
433436
}
434437

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

439-
Drop { ref value, target, .. } => {
440-
let ptr = self.eval_lvalue(value)?.to_ptr();
441-
let ty = self.lvalue_ty(value);
442+
Drop { ref location, target, .. } => {
443+
let ptr = self.eval_lvalue(location)?.to_ptr();
444+
let ty = self.lvalue_ty(location);
442445
self.drop(ptr, ty)?;
443446
self.frame_mut().next_block = target;
444447
}
445448

449+
Assert { ref cond, expected, ref msg, target, cleanup } => {
450+
let actual_ptr = self.eval_operand(cond)?;
451+
let actual = self.memory.read_bool(actual_ptr)?;
452+
if actual == expected {
453+
self.frame_mut().next_block = target;
454+
} else {
455+
panic!("unimplemented: jump to {:?} and print {:?}", cleanup, msg);
456+
}
457+
}
458+
459+
DropAndReplace { .. } => unimplemented!(),
446460
Resume => unimplemented!(),
461+
Unreachable => unimplemented!(),
447462
}
448463

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

885+
// FIXME(solson): Factor this out with BinaryOp.
886+
CheckedBinaryOp(bin_op, ref left, ref right) => {
887+
let left_ptr = self.eval_operand(left)?;
888+
let left_ty = self.operand_ty(left);
889+
let left_val = self.read_primval(left_ptr, left_ty)?;
890+
891+
let right_ptr = self.eval_operand(right)?;
892+
let right_ty = self.operand_ty(right);
893+
let right_val = self.read_primval(right_ptr, right_ty)?;
894+
895+
let val = primval::binary_op(bin_op, left_val, right_val)?;
896+
self.memory.write_primval(dest, val)?;
897+
898+
// FIXME(solson): Find the result type size properly. Perhaps refactor out
899+
// Projection calculations so we can do the equivalent of `dest.1` here.
900+
let s = self.type_size(left_ty, self.substs());
901+
self.memory.write_bool(dest.offset(s as isize), false)?;
902+
}
903+
870904
UnaryOp(un_op, ref operand) => {
871905
let ptr = self.eval_operand(operand)?;
872906
let ty = self.operand_ty(operand);
@@ -1048,7 +1082,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
10481082
}
10491083
}
10501084

1051-
Slice { .. } => unimplemented!(),
10521085
InlineAsm { .. } => unimplemented!(),
10531086
}
10541087

@@ -1161,9 +1194,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
11611194
let ptr = match *lvalue {
11621195
ReturnPointer => self.frame().return_ptr
11631196
.expect("ReturnPointer used in a function with no return value"),
1164-
Arg(i) => self.frame().locals[i as usize],
1165-
Var(i) => self.frame().locals[self.frame().var_offset + i as usize],
1166-
Temp(i) => self.frame().locals[self.frame().temp_offset + i as usize],
1197+
Arg(i) => self.frame().locals[i.index()],
1198+
Var(i) => self.frame().locals[self.frame().var_offset + i.index()],
1199+
Temp(i) => self.frame().locals[self.frame().temp_offset + i.index()],
11671200

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

12501283
ConstantIndex { .. } => unimplemented!(),
1284+
Subslice { .. } => unimplemented!(),
12511285
}
12521286
}
12531287
};

src/interpreter/stepper.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ impl<'ecx, 'a, 'tcx> Stepper<'ecx, 'a, 'tcx> {
5151
let block = self.ecx.frame().next_block;
5252
let stmt = self.ecx.frame().stmt;
5353
let mir = self.ecx.mir();
54-
let basic_block = mir.basic_block_data(block);
54+
let basic_block = &mir.basic_blocks()[block];
5555

5656
if let Some(ref stmt) = basic_block.statements.get(stmt) {
5757
let current_stack = self.ecx.stack.len();
5858
ConstantExtractor {
59-
span: stmt.span,
59+
span: stmt.source_info.span,
6060
substs: self.ecx.substs(),
6161
def_id: self.ecx.frame().def_id,
6262
ecx: self.ecx,
@@ -75,7 +75,7 @@ impl<'ecx, 'a, 'tcx> Stepper<'ecx, 'a, 'tcx> {
7575
let terminator = basic_block.terminator();
7676
let current_stack = self.ecx.stack.len();
7777
ConstantExtractor {
78-
span: terminator.span,
78+
span: terminator.source_info.span,
7979
substs: self.ecx.substs(),
8080
def_id: self.ecx.frame().def_id,
8181
ecx: self.ecx,

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
// From rustc.
1313
#[macro_use] extern crate rustc;
14+
extern crate rustc_data_structures;
1415
extern crate rustc_mir;
1516
extern crate rustc_trans;
1617
extern crate syntax;

tests/compiletest.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ fn run_mode(mode: &'static str) {
2727
fn compile_test() {
2828
run_mode("compile-fail");
2929
run_mode("run-pass");
30-
run_mode("run-fail");
3130
}

tests/run-fail/inception.rs

-50
This file was deleted.

0 commit comments

Comments
 (0)