diff options
| author | Ralf Jung <post@ralfj.de> | 2017-08-26 13:51:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-26 13:51:13 +0200 |
| commit | 2307d6fc5bbc71ad961f0d80b8d532194968be0b (patch) | |
| tree | 59879e3607352a5fbd38fd0c411872b21d15e236 | |
| parent | 8ce6b06d52e6b0792d9f6c3bc192cbcfb21842f1 (diff) | |
| parent | 54a1f079b8bbde11cf9690452430448515743bb5 (diff) | |
| download | rust-2307d6fc5bbc71ad961f0d80b8d532194968be0b.tar.gz rust-2307d6fc5bbc71ad961f0d80b8d532194968be0b.zip | |
Merge branch 'master' into memory
| -rw-r--r-- | Cargo.lock | 66 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/terminator/drop.rs | 59 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/terminator/mod.rs | 4 | ||||
| -rw-r--r-- | tests/compiletest.rs | 14 |
5 files changed, 104 insertions, 40 deletions
diff --git a/Cargo.lock b/Cargo.lock index 3eb59878271..9e41c301087 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,6 +42,11 @@ dependencies = [ ] [[package]] +name = "bitflags" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "byteorder" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -63,7 +68,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "compiletest_rs" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -71,6 +76,19 @@ dependencies = [ ] [[package]] +name = "conv" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "custom_derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "dbghelp-sys" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -136,6 +154,23 @@ dependencies = [ ] [[package]] +name = "magenta" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "magenta-sys" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "memchr" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -149,11 +184,12 @@ version = "0.1.0" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "compiletest_rs 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "compiletest_rs 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_miri 0.1.0", + "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -167,6 +203,15 @@ version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "rand" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "regex" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -247,6 +292,14 @@ dependencies = [ ] [[package]] +name = "tempdir" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "thread_local" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -292,10 +345,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699" "checksum backtrace 0.3.2 (git+https://github.com/alexcrichton/backtrace-rs)" = "<none>" "checksum backtrace-sys 0.1.12 (git+https://github.com/alexcrichton/backtrace-rs)" = "<none>" +"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" "checksum cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "be1057b8462184f634c3a208ee35b0f935cfd94b694b26deadccd98732088d7b" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" -"checksum compiletest_rs 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "617b23d0ed4f57b3bcff6b5fe0a78f0010f1efb636298317665a960b6dbc0533" +"checksum compiletest_rs 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3dc4720203de7b490e2808cad3e9090e8850eed4ecd4176b246551a952f4ead7" +"checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299" +"checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" "checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90" "checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" @@ -306,9 +362,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb7b49972ee23d8aa1026c365a5b440ba08e35075f18c459980c7395c221ec48" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3d382732ea0fbc09790c4899db3255bdea0fc78b54bf234bd18a63bb603915b6" +"checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" +"checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" "checksum num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "99843c856d68d8b4313b03a17e33c4bb42ae8f6610ea81b28abe076ac721b9b0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" +"checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf" "checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" "checksum rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95" @@ -319,6 +378,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "48b04779552e92037212c3615370f6bd57a40ebba7f20e554ff9f55e41a69a7b" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" +"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" "checksum thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" diff --git a/Cargo.toml b/Cargo.toml index 5f4a87eca42..0985c15aece 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ cargo_miri = ["cargo_metadata"] [dev-dependencies] compiletest_rs = "0.2.6" +tempdir = "0.3" [workspace] exclude = ["xargo", "cargo-miri-test", "rustc_tests"] diff --git a/src/librustc_mir/interpret/terminator/drop.rs b/src/librustc_mir/interpret/terminator/drop.rs index 32a4c66df2a..6596cf951fd 100644 --- a/src/librustc_mir/interpret/terminator/drop.rs +++ b/src/librustc_mir/interpret/terminator/drop.rs @@ -1,8 +1,8 @@ -use rustc::mir; +use rustc::mir::BasicBlock; use rustc::ty::{self, Ty}; use syntax::codemap::Span; -use interpret::{EvalResult, EvalContext, StackPopCleanup, Lvalue, LvalueExtra, PrimVal, Value, +use interpret::{EvalResult, EvalContext, Lvalue, LvalueExtra, PrimVal, Value, Machine, ValTy}; impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { @@ -12,6 +12,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { instance: ty::Instance<'tcx>, ty: Ty<'tcx>, span: Span, + target: BasicBlock, ) -> EvalResult<'tcx> { trace!("drop_lvalue: {:#?}", lval); // We take the address of the object. This may well be unaligned, which is fine for us here. @@ -32,57 +33,51 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { } => ptr.ptr.to_value(), _ => bug!("force_allocation broken"), }; - self.drop(val, instance, ty, span) + self.drop(val, instance, ty, span, target) } - pub(crate) fn drop( + + fn drop( &mut self, arg: Value, - mut instance: ty::Instance<'tcx>, + instance: ty::Instance<'tcx>, ty: Ty<'tcx>, span: Span, + target: BasicBlock, ) -> EvalResult<'tcx> { trace!("drop: {:#?}, {:?}, {:?}", arg, ty.sty, instance.def); - if let ty::InstanceDef::DropGlue(_, None) = instance.def { - trace!("nothing to do, aborting"); - // we don't actually need to drop anything - return Ok(()); - } - let mir = match ty.sty { + let instance = match ty.sty { ty::TyDynamic(..) => { let vtable = match arg { Value::ByValPair(_, PrimVal::Ptr(vtable)) => vtable, _ => bug!("expected fat ptr, got {:?}", arg), }; match self.read_drop_type_from_vtable(vtable)? { - Some(func) => { - instance = func; - self.load_mir(func.def)? - } + Some(func) => func, // no drop fn -> bail out - None => return Ok(()), + None => { + self.goto_block(target); + return Ok(()) + }, } } - _ => self.load_mir(instance.def)?, + _ => instance, }; - self.push_stack_frame( - instance, - span, - mir, - Lvalue::undef(), - StackPopCleanup::None, - )?; - - let mut arg_locals = self.frame().mir.args_iter(); - assert_eq!(self.frame().mir.arg_count, 1); - let arg_local = arg_locals.next().unwrap(); - let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?; - let arg_ty = self.tcx.mk_mut_ptr(ty); + // the drop function expects a reference to the value let valty = ValTy { value: arg, - ty: arg_ty, + ty: self.tcx.mk_mut_ptr(ty), }; - self.write_value(valty, dest) + + let fn_sig = self.tcx.fn_sig(instance.def_id()).skip_binder().clone(); + + self.eval_fn_call( + instance, + Some((Lvalue::undef(), target)), + &vec![valty], + span, + fn_sig, + ) } } diff --git a/src/librustc_mir/interpret/terminator/mod.rs b/src/librustc_mir/interpret/terminator/mod.rs index bd6aabc3621..60893fcec18 100644 --- a/src/librustc_mir/interpret/terminator/mod.rs +++ b/src/librustc_mir/interpret/terminator/mod.rs @@ -111,12 +111,11 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { target, .. } => { - trace!("TerminatorKind::drop: {:?}, {:?}", location, self.substs()); // FIXME(CTFE): forbid drop in const eval let lval = self.eval_lvalue(location)?; let ty = self.lvalue_ty(location); - self.goto_block(target); let ty = eval_context::apply_param_substs(self.tcx, self.substs(), &ty); + trace!("TerminatorKind::drop: {:?}, type {}", location, ty); let instance = eval_context::resolve_drop_in_place(self.tcx, ty); self.drop_lvalue( @@ -124,6 +123,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { instance, ty, terminator.source_info.span, + target, )?; } diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 35c5e82803f..7a220ec7627 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -1,10 +1,12 @@ #![feature(slice_concat_ext)] extern crate compiletest_rs as compiletest; +extern crate tempdir; use std::slice::SliceConcatExt; use std::path::{PathBuf, Path}; use std::io::Write; +use tempdir::TempDir; macro_rules! eprintln { ($($arg:tt)*) => { @@ -35,8 +37,10 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, fullmir: b path, target ); - let mut config = compiletest::default_config(); + let build_dir = TempDir::new("miri-tests").unwrap(); + let mut config = compiletest::Config::default(); config.mode = "compile-fail".parse().expect("Invalid mode"); + config.build_base = build_dir.path().to_owned(); config.rustc_path = miri_path(); let mut flags = Vec::new(); if rustc_test_suite().is_some() { @@ -66,8 +70,10 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, fullmir: b fn run_pass(path: &str) { eprintln!("## Running run-pass tests in {} against rustc", path); - let mut config = compiletest::default_config(); + let build_dir = TempDir::new("miri-tests").unwrap(); + let mut config = compiletest::Config::default(); config.mode = "run-pass".parse().expect("Invalid mode"); + config.build_base = build_dir.path().to_owned(); config.src_base = PathBuf::from(path); if let Some(rustc_path) = rustc_test_suite() { config.rustc_path = rustc_path; @@ -89,8 +95,10 @@ fn miri_pass(path: &str, target: &str, host: &str, fullmir: bool, opt: bool) { target, opt_str ); - let mut config = compiletest::default_config(); + let build_dir = TempDir::new("miri-tests").unwrap(); + let mut config = compiletest::Config::default(); config.mode = "mir-opt".parse().expect("Invalid mode"); + config.build_base = build_dir.path().to_owned(); config.src_base = PathBuf::from(path); config.target = target.to_owned(); config.host = host.to_owned(); |
