-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
don't use #[miri_run]
anymore, but execute the main
function
#23
Changes from 1 commit
55fd060
1bd00e8
8abd293
a55ac1f
d82a792
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
#![feature(custom_attribute)] | ||
#![allow(unused_attributes)] | ||
|
||
#[miri_run] | ||
#[inline(never)] | ||
pub fn main() { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,10 @@ use rustc::session::Session; | |
use rustc_driver::{driver, CompilerCalls}; | ||
use rustc::ty::{TyCtxt, subst}; | ||
use rustc::mir::mir_map::MirMap; | ||
use rustc::mir::repr::Mir; | ||
use rustc::hir::def_id::DefId; | ||
use rustc::hir::{map, ItemFn, Item}; | ||
use syntax::codemap::Span; | ||
|
||
struct MiriCompilerCalls; | ||
|
||
|
@@ -34,58 +37,46 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { | |
|
||
control.after_analysis.callback = Box::new(|state| { | ||
state.session.abort_if_errors(); | ||
interpret_start_points(state.tcx.unwrap(), state.mir_map.unwrap()); | ||
|
||
let tcx = state.tcx.unwrap(); | ||
let mir_map = state.mir_map.unwrap(); | ||
let (span, mir, def_id) = get_main(tcx, mir_map); | ||
println!("found `main` function at: {:?}", span); | ||
|
||
let mut ecx = EvalContext::new(tcx, mir_map); | ||
let substs = tcx.mk_substs(subst::Substs::empty()); | ||
let return_ptr = ecx.alloc_ret_ptr(mir.return_ty, substs).expect("main function should not be diverging"); | ||
|
||
ecx.push_stack_frame(def_id, mir.span, CachedMir::Ref(mir), substs, Some(return_ptr)); | ||
|
||
loop { | ||
match step(&mut ecx) { | ||
Ok(true) => {} | ||
Ok(false) => break, | ||
// FIXME: diverging functions can end up here in some future miri | ||
Err(e) => { | ||
report(tcx, &ecx, e); | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
control | ||
} | ||
} | ||
|
||
|
||
|
||
fn interpret_start_points<'a, 'tcx>( | ||
tcx: TyCtxt<'a, 'tcx, 'tcx>, | ||
mir_map: &MirMap<'tcx>, | ||
) { | ||
let initial_indentation = ::log_settings::settings().indentation; | ||
fn get_main<'a, 'b, 'tcx: 'b>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &'b MirMap<'tcx>) -> (Span, &'b Mir<'tcx>, DefId) { | ||
for (&id, mir) in &mir_map.map { | ||
for attr in tcx.map.attrs(id) { | ||
use syntax::attr::AttrMetaMethods; | ||
if attr.check_name("miri_run") { | ||
let item = tcx.map.expect_item(id); | ||
|
||
::log_settings::settings().indentation = initial_indentation; | ||
|
||
debug!("Interpreting: {}", item.name); | ||
|
||
let mut ecx = EvalContext::new(tcx, mir_map); | ||
let substs = tcx.mk_substs(subst::Substs::empty()); | ||
let return_ptr = ecx.alloc_ret_ptr(mir.return_ty, substs); | ||
|
||
ecx.push_stack_frame(tcx.map.local_def_id(id), mir.span, CachedMir::Ref(mir), substs, return_ptr); | ||
|
||
loop { | ||
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; | ||
} | ||
// FIXME: diverging functions can end up here in some future miri | ||
Err(e) => { | ||
report(tcx, &ecx, e); | ||
break; | ||
} | ||
} | ||
if let map::Node::NodeItem(&Item { name, span, ref node, .. }) = tcx.map.get(id) { | ||
if let ItemFn(..) = *node { | ||
if name.as_str() == "main" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method doesn't account for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return (span, mir, tcx.map.local_def_id(id)); | ||
} | ||
} | ||
} | ||
} | ||
panic!("no main function found"); | ||
} | ||
|
||
fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
fn main() { | ||
let p = { | ||
let b = Box::new(42); | ||
&*b as *const i32 | ||
}; | ||
let x = unsafe { *p }; //~ ERROR: dangling pointer was dereferenced | ||
panic!("this should never print: {}", x); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
#![feature(custom_attribute)] | ||
#![allow(dead_code, unused_attributes)] | ||
|
||
fn f() {} | ||
|
||
#[miri_run] | ||
fn deref_fn_ptr() -> i32 { | ||
unsafe { | ||
fn main() { | ||
let x: i32 = unsafe { | ||
*std::mem::transmute::<fn(), *const i32>(f) //~ ERROR: tried to dereference a function pointer | ||
} | ||
}; | ||
panic!("this should never print: {}", x); | ||
} | ||
|
||
fn main() {} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
#![feature(custom_attribute, box_syntax)] | ||
#![allow(dead_code, unused_attributes)] | ||
#![feature(box_syntax)] | ||
|
||
#[miri_run] | ||
fn deref_fn_ptr() { | ||
fn main() { | ||
//FIXME: this span is wrong | ||
let x = box 42; //~ ERROR: tried to treat a memory pointer as a function pointer | ||
unsafe { | ||
let f = std::mem::transmute::<Box<i32>, fn()>(x); | ||
f() | ||
} | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
let b = unsafe { std::mem::transmute::<u8, bool>(2) }; | ||
if b { unreachable!() } else { unreachable!() } //~ ERROR: invalid boolean value read | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR: attempted to interpret some raw bytes as a pointer address | ||
panic!("this should never print: {}", x); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() { | ||
let v: Vec<u8> = vec![1, 2]; | ||
let x = unsafe { *v.get_unchecked(5) }; //~ ERROR: memory access of 5..6 outside bounds of allocation 29 which has size 2 | ||
panic!("this should never print: {}", x); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fn main() { | ||
let mut p = &42; | ||
unsafe { | ||
let ptr: *mut _ = &mut p; | ||
*(ptr as *mut u8) = 123; // if we ever support 8 bit pointers, this is gonna cause | ||
// "attempted to interpret some raw bytes as a pointer address" instead of | ||
// "attempted to read undefined bytes" | ||
} | ||
let x = *p; //~ ERROR: attempted to read undefined bytes | ||
panic!("this should never print: {}", x); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() { | ||
let x: *const u8 = &1; | ||
let y: *const u8 = &2; | ||
if x < y { //~ ERROR: attempted to do math or a comparison on pointers into different allocations | ||
unreachable!() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() { | ||
let v: Vec<u8> = Vec::with_capacity(10); | ||
let undef = unsafe { *v.get_unchecked(5) }; | ||
let x = undef + 1; //~ ERROR: attempted to read undefined bytes | ||
panic!("this should never print: {}", x); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,5 @@ | ||
#![feature(custom_attribute)] | ||
#![allow(dead_code, unused_attributes)] | ||
|
||
//error-pattern:begin_panic_fmt | ||
|
||
|
||
#[miri_run] | ||
fn failed_assertions() { | ||
fn main() { | ||
assert_eq!(5, 6); | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() { | ||
let p = 42 as *const i32; | ||
let x = unsafe { *p }; //~ ERROR: attempted to interpret some raw bytes as a pointer address | ||
panic!("this should never print: {}", x); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ fn run_mode(mode: &'static str) { | |
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust") | ||
.to_owned(), | ||
}; | ||
let sysroot_flag = format!("--sysroot {}", sysroot); | ||
let sysroot_flag = format!("--sysroot {} -Dwarnings", sysroot); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so our compile-fail tests don't contain unnecessary warnings anymore... like functions that are never called (those had There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, okay. I guess rename |
||
|
||
// FIXME: read directories in sysroot/lib/rustlib and generate the test targets from that | ||
let targets = &["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use a logging macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a
println
in the overall diff https://github.com/solson/miri/pull/23/files#diff-c3d602c5c8035a16699ce9c015bfeceaR41There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops, sorry, wanted to make that its own commit