Skip to content

Commit f789c40

Browse files
authored
Merge pull request rust-lang#94 from solson/revert-93-always_encode_mir
Revert "rustup to rustc 1.15.0-dev (ace092f 2016-12-13)"
2 parents cbffb3b + 0deabf9 commit f789c40

File tree

8 files changed

+78
-97
lines changed

8 files changed

+78
-97
lines changed

src/bin/miri.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern crate syntax;
1010
#[macro_use] extern crate log;
1111

1212
use rustc::session::Session;
13-
use rustc_driver::CompilerCalls;
13+
use rustc_driver::{CompilerCalls, Compilation};
1414
use rustc_driver::driver::{CompileState, CompileController};
1515
use syntax::ast::{MetaItemKind, NestedMetaItemKind};
1616

@@ -21,6 +21,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
2121
let mut control = CompileController::basic();
2222
control.after_hir_lowering.callback = Box::new(after_hir_lowering);
2323
control.after_analysis.callback = Box::new(after_analysis);
24+
control.after_analysis.stop = Compilation::Stop;
2425
control
2526
}
2627
}
@@ -34,16 +35,14 @@ fn after_analysis(state: &mut CompileState) {
3435
state.session.abort_if_errors();
3536

3637
let tcx = state.tcx.unwrap();
37-
if let Some((entry_node_id, _)) = *state.session.entry_fn.borrow() {
38-
let entry_def_id = tcx.map.local_def_id(entry_node_id);
39-
let limits = resource_limits_from_attributes(state);
40-
miri::run_mir_passes(tcx);
41-
miri::eval_main(tcx, entry_def_id, limits);
42-
43-
state.session.abort_if_errors();
44-
} else {
45-
println!("no main function found, assuming auxiliary build");
46-
}
38+
let (entry_node_id, _) = state.session.entry_fn.borrow()
39+
.expect("no main or start function found");
40+
let entry_def_id = tcx.map.local_def_id(entry_node_id);
41+
let limits = resource_limits_from_attributes(state);
42+
miri::run_mir_passes(tcx);
43+
miri::eval_main(tcx, entry_def_id, limits);
44+
45+
state.session.abort_if_errors();
4746
}
4847

4948
fn resource_limits_from_attributes(state: &CompileState) -> miri::ResourceLimits {
@@ -135,7 +134,6 @@ fn main() {
135134
args.push(sysroot_flag);
136135
args.push(find_sysroot());
137136
}
138-
args.push("-Zalways-encode-mir".to_owned());
139137

140138
rustc_driver::run_compiler(&args, &mut MiriCompilerCalls, None, None);
141139
}

src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use syntax::codemap::Span;
1111
pub enum EvalError<'tcx> {
1212
FunctionPointerTyMismatch(Abi, &'tcx FnSig<'tcx>, &'tcx BareFnTy<'tcx>),
1313
NoMirFor(String),
14-
UnterminatedCString(Pointer),
1514
DanglingPointerDeref,
1615
InvalidMemoryAccess,
1716
InvalidFunctionPointer,
@@ -120,8 +119,6 @@ impl<'tcx> Error for EvalError<'tcx> {
120119
"tried to deallocate frozen memory",
121120
EvalError::Layout(_) =>
122121
"rustc layout computation failed",
123-
EvalError::UnterminatedCString(_) =>
124-
"attempted to get length of a null terminated string, but no null found before end of allocation",
125122
}
126123
}
127124

src/memory.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -530,22 +530,6 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
530530
Ok(())
531531
}
532532

533-
pub fn read_c_str(&self, ptr: Pointer) -> EvalResult<'tcx, &[u8]> {
534-
let alloc = self.get(ptr.alloc_id)?;
535-
assert_eq!(ptr.offset as usize as u64, ptr.offset);
536-
let offset = ptr.offset as usize;
537-
match alloc.bytes[offset..].iter().position(|&c| c == 0) {
538-
Some(size) => {
539-
if self.relocations(ptr, (size + 1) as u64)?.count() != 0 {
540-
return Err(EvalError::ReadPointerAsBytes);
541-
}
542-
self.check_defined(ptr, (size + 1) as u64)?;
543-
Ok(&alloc.bytes[offset..offset + size])
544-
},
545-
None => Err(EvalError::UnterminatedCString(ptr)),
546-
}
547-
}
548-
549533
pub fn read_bytes(&self, ptr: Pointer, size: u64) -> EvalResult<'tcx, &[u8]> {
550534
self.get_bytes(ptr, size, 1)
551535
}

src/terminator/intrinsic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
5757
}
5858

5959
"atomic_load" |
60-
"atomic_load_relaxed" |
6160
"atomic_load_acq" |
6261
"volatile_load" => {
6362
let ty = substs.type_at(0);

src/terminator/mod.rs

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
9090
ty::TyFnPtr(bare_fn_ty) => {
9191
let fn_ptr = self.eval_operand_to_primval(func)?.to_ptr();
9292
let (def_id, substs, abi, sig) = self.memory.get_fn(fn_ptr.alloc_id)?;
93-
let bare_sig = self.tcx.erase_late_bound_regions_and_normalize(&bare_fn_ty.sig);
94-
let bare_sig = self.tcx.erase_regions(&bare_sig);
95-
// transmuting function pointers in miri is fine as long as the number of
96-
// arguments and the abi don't change.
97-
// FIXME: also check the size of the arguments' type and the return type
98-
// Didn't get it to work, since that triggers an assertion in rustc which
99-
// checks whether the type has escaping regions
100-
if abi != bare_fn_ty.abi ||
101-
sig.variadic != bare_sig.variadic ||
102-
sig.inputs().len() != bare_sig.inputs().len() {
93+
if abi != bare_fn_ty.abi || sig != bare_fn_ty.sig.skip_binder() {
10394
return Err(EvalError::FunctionPointerTyMismatch(abi, sig, bare_fn_ty));
10495
}
10596
self.eval_fn_call(def_id, substs, bare_fn_ty, destination, args,
@@ -198,15 +189,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
198189
use syntax::abi::Abi;
199190
match fn_ty.abi {
200191
Abi::RustIntrinsic => {
201-
let ty = fn_ty.sig.0.output();
192+
let ty = fn_ty.sig.0.output;
202193
let layout = self.type_layout(ty)?;
203194
let (ret, target) = destination.unwrap();
204195
self.call_intrinsic(def_id, substs, arg_operands, ret, ty, layout, target)?;
205196
Ok(())
206197
}
207198

208199
Abi::C => {
209-
let ty = fn_ty.sig.0.output();
200+
let ty = fn_ty.sig.0.output;
210201
let (ret, target) = destination.unwrap();
211202
self.call_c_abi(def_id, arg_operands, ret, ty)?;
212203
self.goto_block(target);
@@ -329,6 +320,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
329320
.collect();
330321
let args = args_res?;
331322

323+
if link_name.starts_with("pthread_") {
324+
warn!("ignoring C ABI call: {}", link_name);
325+
return Ok(());
326+
}
327+
332328
let usize = self.tcx.types.usize;
333329

334330
match &link_name[..] {
@@ -375,37 +371,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
375371
self.write_primval(dest, PrimVal::new(result as u64), dest_ty)?;
376372
}
377373

378-
"memchr" => {
379-
let ptr = args[0].read_ptr(&self.memory)?;
380-
let val = self.value_to_primval(args[1], usize)?.to_u64() as u8;
381-
let num = self.value_to_primval(args[2], usize)?.to_u64();
382-
if let Some(idx) = self.memory.read_bytes(ptr, num)?.iter().position(|&c| c == val) {
383-
let new_ptr = ptr.offset(idx as u64);
384-
self.write_value(Value::ByVal(PrimVal::from_ptr(new_ptr)), dest, dest_ty)?;
385-
} else {
386-
self.write_value(Value::ByVal(PrimVal::new(0)), dest, dest_ty)?;
387-
}
388-
}
389-
390-
"getenv" => {
391-
{
392-
let name_ptr = args[0].read_ptr(&self.memory)?;
393-
let name = self.memory.read_c_str(name_ptr)?;
394-
info!("ignored env var request for `{:?}`", ::std::str::from_utf8(name));
395-
}
396-
self.write_value(Value::ByVal(PrimVal::new(0)), dest, dest_ty)?;
397-
}
398-
399-
// unix panic code inside libstd will read the return value of this function
400-
"pthread_rwlock_rdlock" => {
401-
self.write_primval(dest, PrimVal::new(0), dest_ty)?;
402-
}
403-
404-
link_name if link_name.starts_with("pthread_") => {
405-
warn!("ignoring C ABI call: {}", link_name);
406-
return Ok(());
407-
},
408-
409374
_ => {
410375
return Err(EvalError::Unimplemented(format!("can't call C ABI function: {}", link_name)));
411376
}
@@ -555,7 +520,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
555520
let offset = idx * self.memory.pointer_size();
556521
let fn_ptr = self.memory.read_ptr(vtable.offset(offset))?;
557522
let (def_id, substs, _abi, sig) = self.memory.get_fn(fn_ptr.alloc_id)?;
558-
*first_ty = sig.inputs()[0];
523+
*first_ty = sig.inputs[0];
559524
Ok((def_id, substs, Vec::new()))
560525
} else {
561526
Err(EvalError::VtableForArgumentlessMethod)
@@ -699,7 +664,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
699664
// some values don't need to call a drop impl, so the value is null
700665
if drop_fn != Pointer::from_int(0) {
701666
let (def_id, substs, _abi, sig) = self.memory.get_fn(drop_fn.alloc_id)?;
702-
let real_ty = sig.inputs()[0];
667+
let real_ty = sig.inputs[0];
703668
self.drop(Lvalue::from_ptr(ptr), real_ty, drop)?;
704669
drop.push((def_id, Value::ByVal(PrimVal::from_ptr(ptr)), substs));
705670
} else {

tests/compiletest.rs

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ fn run_pass() {
2727
compiletest::run_tests(&config);
2828
}
2929

30-
fn miri_pass(path: &str, target: &str) {
31-
let mut config = compiletest::default_config();
32-
config.mode = "mir-opt".parse().expect("Invalid mode");
33-
config.src_base = PathBuf::from(path);
34-
config.target = target.to_owned();
35-
config.rustc_path = PathBuf::from("target/debug/miri");
36-
compiletest::run_tests(&config);
37-
}
38-
3930
fn for_all_targets<F: FnMut(String)>(sysroot: &str, mut f: F) {
4031
for target in std::fs::read_dir(format!("{}/lib/rustlib/", sysroot)).unwrap() {
4132
let target = target.unwrap();
@@ -66,10 +57,65 @@ fn compile_test() {
6657
};
6758
run_pass();
6859
for_all_targets(&sysroot, |target| {
69-
miri_pass("tests/run-pass", &target);
70-
if let Ok(path) = std::env::var("MIRI_RUSTC_TEST") {
71-
miri_pass(&path, &target);
60+
let files = std::fs::read_dir("tests/run-pass").unwrap();
61+
let files: Box<Iterator<Item=_>> = if let Ok(path) = std::env::var("MIRI_RUSTC_TEST") {
62+
Box::new(files.chain(std::fs::read_dir(path).unwrap()))
63+
} else {
64+
Box::new(files)
65+
};
66+
let mut mir_not_found = 0;
67+
let mut crate_not_found = 0;
68+
let mut success = 0;
69+
let mut failed = 0;
70+
for file in files {
71+
let file = file.unwrap();
72+
let path = file.path();
73+
74+
if !file.metadata().unwrap().is_file() || !path.to_str().unwrap().ends_with(".rs") {
75+
continue;
76+
}
77+
78+
let stderr = std::io::stderr();
79+
write!(stderr.lock(), "test [miri-pass] {} ... ", path.display()).unwrap();
80+
let mut cmd = std::process::Command::new("target/debug/miri");
81+
cmd.arg(path);
82+
cmd.arg(format!("--target={}", target));
83+
let libs = Path::new(&sysroot).join("lib");
84+
let sysroot = libs.join("rustlib").join(&target).join("lib");
85+
let paths = std::env::join_paths(&[libs, sysroot]).unwrap();
86+
cmd.env(compiletest::procsrv::dylib_env_var(), paths);
87+
88+
match cmd.output() {
89+
Ok(ref output) if output.status.success() => {
90+
success += 1;
91+
writeln!(stderr.lock(), "ok").unwrap()
92+
},
93+
Ok(output) => {
94+
let output_err = std::str::from_utf8(&output.stderr).unwrap();
95+
if let Some(text) = output_err.splitn(2, "no mir for `").nth(1) {
96+
mir_not_found += 1;
97+
let end = text.find('`').unwrap();
98+
writeln!(stderr.lock(), "NO MIR FOR `{}`", &text[..end]).unwrap();
99+
} else if let Some(text) = output_err.splitn(2, "can't find crate for `").nth(1) {
100+
crate_not_found += 1;
101+
let end = text.find('`').unwrap();
102+
writeln!(stderr.lock(), "CAN'T FIND CRATE FOR `{}`", &text[..end]).unwrap();
103+
} else {
104+
failed += 1;
105+
writeln!(stderr.lock(), "FAILED with exit code {:?}", output.status.code()).unwrap();
106+
writeln!(stderr.lock(), "stdout: \n {}", std::str::from_utf8(&output.stdout).unwrap()).unwrap();
107+
writeln!(stderr.lock(), "stderr: \n {}", output_err).unwrap();
108+
}
109+
}
110+
Err(e) => {
111+
writeln!(stderr.lock(), "FAILED: {}", e).unwrap();
112+
panic!("failed to execute miri");
113+
},
114+
}
72115
}
116+
let stderr = std::io::stderr();
117+
writeln!(stderr.lock(), "{} success, {} mir not found, {} crate not found, {} failed", success, mir_not_found, crate_not_found, failed).unwrap();
118+
assert_eq!(failed, 0, "some tests failed");
73119
});
74120
compile_fail(&sysroot);
75121
}

tests/run-pass/aux_test.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/run-pass/auxiliary/dep.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)