Skip to content

Commit 471944b

Browse files
authored
Merge pull request #381 from solson/sanity_checks
Update to rustc sanity check branch
2 parents 79d0a01 + bb6e7c8 commit 471944b

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cargo-features = ["default-run"]
2-
31
[package]
42
authors = ["Scott Olson <[email protected]>"]
53
description = "An experimental interpreter for Rust MIR."
@@ -8,7 +6,6 @@ name = "miri"
86
repository = "https://github.com/solson/miri"
97
version = "0.1.0"
108
build = "build.rs"
11-
default-run = "miri"
129

1310
[[bin]]
1411
doc = false
@@ -33,5 +30,5 @@ log = "0.4"
3330
cargo_miri = ["cargo_metadata"]
3431

3532
[dev-dependencies]
36-
compiletest_rs = { version = "0.3.4", features = ["tmp"] }
33+
compiletest_rs = { version = "0.3.12", features = ["tmp"] }
3734
colored = "1.6"

src/intrinsic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,11 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
245245

246246
"discriminant_value" => {
247247
let ty = substs.type_at(0);
248+
let layout = self.layout_of(ty)?;
248249
let adt_ptr = self.into_ptr(args[0].value)?;
249250
let adt_align = self.layout_of(args[0].ty)?.align;
250251
let place = Place::from_scalar_ptr(adt_ptr, adt_align);
251-
let discr_val = self.read_discriminant_value(place, ty)?;
252+
let discr_val = self.read_discriminant_value(place, layout)?;
252253
self.write_scalar(dest, Scalar::from_u128(discr_val), dest_layout.ty)?;
253254
}
254255

@@ -343,7 +344,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
343344
ty::layout::Abi::Scalar(_) => Value::Scalar(Scalar::null()),
344345
_ => {
345346
// FIXME(oli-obk): pass TyLayout to alloc_ptr instead of Ty
346-
let ptr = this.alloc_ptr(dest_layout.ty)?;
347+
let ptr = this.alloc_ptr(dest_layout)?;
347348
let ptr = Scalar::Ptr(ptr);
348349
this.memory.write_repeat(ptr, 0, size)?;
349350
Value::ByRef(ptr, dest_layout.align)

src/validation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
140140
mir::Place::Static(ref s) => AbsPlace::Static(s.def_id),
141141
mir::Place::Projection(ref p) =>
142142
AbsPlace::Projection(Box::new(self.abstract_place_projection(&*p)?)),
143+
_ => unimplemented!("validation is not currently maintained"),
143144
})
144145
}
145146

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

766767
match adt.adt_kind() {
767768
AdtKind::Enum => {
768-
let variant_idx = self.read_discriminant_as_variant_index(query.place.1, query.ty)?;
769+
let layout = self.layout_of(query.ty)?;
770+
let variant_idx = self.read_discriminant_as_variant_index(query.place.1, layout)?;
769771
let variant = &adt.variants[variant_idx];
770772

771773
if !variant.fields.is_empty() {

tests/compile-fail/invalid_bool.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//ignore-test FIXME (do some basic validation of invariants for all values in flight)
2+
13
fn main() {
24
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
35
if b { unreachable!() } else { unreachable!() } //~ ERROR constant evaluation error

tests/compile-fail/modifying_constants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-test FIXME: we are not making these statics read-only any more?
2+
13
fn main() {
24
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
35
let y = unsafe { &mut *(x as *const i32 as *mut i32) };

0 commit comments

Comments
 (0)