未验证 提交 f2d01010 编写于 作者: O Oliver Schneider 提交者: Oliver Schneider

Also test optimized MIR

上级 9710ff48
......@@ -199,11 +199,7 @@ fn main() {
args.push(sysroot_flag);
args.push(find_sysroot());
}
// we run the optimization passes inside miri
// if we ran them twice we'd get funny failures due to borrowck ElaborateDrops only working on
// unoptimized MIR
// FIXME: add an after-mir-passes hook to rustc driver
args.push("-Zmir-opt-level=0".to_owned());
// for auxilary builds in unit tests
args.push("-Zalways-encode-mir".to_owned());
......
......@@ -87,14 +87,9 @@ fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> EvalResult<'tcx> {
match *dest_layout {
Layout::General { discr, .. } => {
// FIXME: I (oli-obk) think we need to check the
// `dest_ty` for the variant's discriminant and write
// instead of the variant index
// We don't have any tests actually going through these lines
let discr_ty = discr.to_ty(&self.tcx, false);
let discr_lval = self.lvalue_field(dest, 0, dest_ty, discr_ty)?;
self.write_value(Value::ByVal(PrimVal::Bytes(variant_index as u128)), discr_lval, discr_ty)?;
let discr_size = discr.size().bytes();
let dest_ptr = self.force_allocation(dest)?.to_ptr()?;
self.memory.write_uint(dest_ptr, variant_index as u128, discr_size)?
}
Layout::RawNullablePointer { nndiscr, .. } => {
......@@ -103,6 +98,17 @@ fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> EvalResult<'tcx> {
}
}
Layout::StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
if variant_index as u64 != nndiscr {
let (offset, ty) = self.nonnull_offset_and_ty(dest_ty, nndiscr, discrfield)?;
let nonnull = self.force_allocation(dest)?.to_ptr()?.offset(offset.bytes(), self.memory.layout)?;
trace!("struct wrapped nullable pointer type: {}", ty);
// only the pointer part of a fat pointer is used for this space optimization
let discr_size = self.type_size(ty)?.expect("bad StructWrappedNullablePointer discrfield");
self.memory.write_uint(nonnull, 0, discr_size)?;
}
},
_ => bug!("SetDiscriminant on {} represented as {:#?}", dest_ty, dest_layout),
}
}
......
#![feature(slice_concat_ext)]
extern crate compiletest_rs as compiletest;
use std::slice::SliceConcatExt;
use std::path::{PathBuf, Path};
use std::io::Write;
......@@ -41,22 +44,34 @@ fn run_pass(path: &str) {
compiletest::run_tests(&config);
}
fn miri_pass(path: &str, target: &str, host: &str, fullmir: bool) {
eprintln!("## Running run-pass tests in {} against miri for target {}", path, target);
fn miri_pass(path: &str, target: &str, host: &str, fullmir: bool, opt: bool) {
let opt_str = if opt {
" with optimizations"
} else {
""
};
eprintln!("## Running run-pass tests in {} against miri for target {}{}", path, target, opt_str);
let mut config = compiletest::default_config();
config.mode = "mir-opt".parse().expect("Invalid mode");
config.src_base = PathBuf::from(path);
config.target = target.to_owned();
config.host = host.to_owned();
config.rustc_path = PathBuf::from("target/debug/miri");
let mut flags = Vec::new();
if fullmir {
if host != target {
// skip fullmir on nonhost
return;
}
let sysroot = Path::new(&std::env::var("HOME").unwrap()).join(".xargo").join("HOST");
config.target_rustcflags = Some(format!("--sysroot {}", sysroot.to_str().unwrap()));
flags.push(format!("--sysroot {}", sysroot.to_str().unwrap()));
}
if opt {
flags.push("-Zmir-opt-level=3".to_owned());
} else {
flags.push("-Zmir-opt-level=0".to_owned());
}
config.target_rustcflags = Some(flags.join(" "));
// don't actually execute the final binary, it might be for other targets and we only care
// about running miri, not the binary.
config.runtool = Some("echo \"\" || ".to_owned());
......@@ -113,10 +128,12 @@ fn run_pass_miri() {
let sysroot = get_sysroot();
let host = get_host();
for_all_targets(&sysroot, |target| {
miri_pass("tests/run-pass", &target, &host, false);
});
miri_pass("tests/run-pass-fullmir", &host, &host, true);
for &opt in [false, true].iter() {
for_all_targets(&sysroot, |target| {
miri_pass("tests/run-pass", &target, &host, false, opt);
});
miri_pass("tests/run-pass-fullmir", &host, &host, true, opt);
}
}
#[test]
......
......@@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// FIXME: remove the next line once https://github.com/rust-lang/rust/issues/43359 is fixed
// compile-flags: -Zmir-opt-level=0
use std::i32;
pub fn main() {
......
......@@ -8,6 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// FIXME: remove the next line when https://github.com/rust-lang/rust/issues/43358 is resolved
// compile-flags: -Zmir-opt-level=0
// Check that you can cast between different pointers to trait objects
// whose vtable have the same kind (both lengths, or both trait pointers).
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册