Skip to content

Update to rustc sanity check branch #381

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

Merged
merged 6 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["default-run"]

[package]
authors = ["Scott Olson <[email protected]>"]
description = "An experimental interpreter for Rust MIR."
Expand All @@ -8,7 +6,6 @@ name = "miri"
repository = "https://github.com/solson/miri"
version = "0.1.0"
build = "build.rs"
default-run = "miri"

[[bin]]
doc = false
Expand All @@ -33,5 +30,5 @@ log = "0.4"
cargo_miri = ["cargo_metadata"]

[dev-dependencies]
compiletest_rs = { version = "0.3.4", features = ["tmp"] }
compiletest_rs = { version = "0.3.12", features = ["tmp"] }
colored = "1.6"
5 changes: 3 additions & 2 deletions src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:

"discriminant_value" => {
let ty = substs.type_at(0);
let layout = self.layout_of(ty)?;
let adt_ptr = self.into_ptr(args[0].value)?;
let adt_align = self.layout_of(args[0].ty)?.align;
let place = Place::from_scalar_ptr(adt_ptr, adt_align);
let discr_val = self.read_discriminant_value(place, ty)?;
let discr_val = self.read_discriminant_value(place, layout)?;
self.write_scalar(dest, Scalar::from_u128(discr_val), dest_layout.ty)?;
}

Expand Down Expand Up @@ -343,7 +344,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
ty::layout::Abi::Scalar(_) => Value::Scalar(Scalar::null()),
_ => {
// FIXME(oli-obk): pass TyLayout to alloc_ptr instead of Ty
let ptr = this.alloc_ptr(dest_layout.ty)?;
let ptr = this.alloc_ptr(dest_layout)?;
let ptr = Scalar::Ptr(ptr);
this.memory.write_repeat(ptr, 0, size)?;
Value::ByRef(ptr, dest_layout.align)
Expand Down
4 changes: 3 additions & 1 deletion src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
mir::Place::Static(ref s) => AbsPlace::Static(s.def_id),
mir::Place::Projection(ref p) =>
AbsPlace::Projection(Box::new(self.abstract_place_projection(&*p)?)),
_ => unimplemented!("validation is not currently maintained"),
})
}

Expand Down Expand Up @@ -765,7 +766,8 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '

match adt.adt_kind() {
AdtKind::Enum => {
let variant_idx = self.read_discriminant_as_variant_index(query.place.1, query.ty)?;
let layout = self.layout_of(query.ty)?;
let variant_idx = self.read_discriminant_as_variant_index(query.place.1, layout)?;
let variant = &adt.variants[variant_idx];

if !variant.fields.is_empty() {
Expand Down
2 changes: 2 additions & 0 deletions tests/compile-fail/invalid_bool.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//ignore-test FIXME (do some basic validation of invariants for all values in flight)

fn main() {
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
if b { unreachable!() } else { unreachable!() } //~ ERROR constant evaluation error
Expand Down
2 changes: 2 additions & 0 deletions tests/compile-fail/modifying_constants.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-test FIXME: we are not making these statics read-only any more?

fn main() {
let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is marked static, not the pointee
let y = unsafe { &mut *(x as *const i32 as *mut i32) };
Expand Down