Skip to content

Commit cf318b1

Browse files
authored
Merge pull request rust-lang#278 from solson/unions
Process untagged unions
2 parents 7700bd0 + f8c61da commit cf318b1

File tree

8 files changed

+101
-73
lines changed

8 files changed

+101
-73
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ script:
2727
- |
2828
# and run all tests with full mir
2929
MIRI_SYSROOT=~/.xargo/HOST cargo test
30+
- |
31+
# test that the rustc_tests binary compiles
32+
cd rustc_tests &&
33+
cargo build &&
34+
cd ..
3035
notifications:
3136
email:
3237
on_success: never

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ rustc_miri = { path = "src/librustc_mir" }
3434
compiletest_rs = "0.2.6"
3535

3636
[workspace]
37-
exclude = ["xargo", "cargo-miri-test"]
37+
exclude = ["xargo", "cargo-miri-test", "rustc_tests"]

miri/fn_call.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
126126
}
127127

128128
"syscall" => {
129+
// TODO: read `syscall` ids like `sysconf` ids and
130+
// figure out some way to actually process some of them
131+
//
132+
// libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)
133+
// is called if a `HashMap` is created the regular way.
129134
match self.value_to_primval(args[0], usize)?.to_u64()? {
135+
318 |
130136
511 => return Err(EvalError::Unimplemented("miri does not support random number generators".to_owned())),
131137
id => return Err(EvalError::Unimplemented(format!("miri does not support syscall id {}", id))),
132138
}

rustc_tests/Cargo.lock

Lines changed: 59 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustc_tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ version = "0.1.0"
44
authors = ["Oliver Schneider <[email protected]>"]
55

66
[dependencies]
7-
miri = { path = "../miri" }
7+
miri = { path = ".." }

rustc_tests/src/main.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,7 @@ fn main() {
149149
args.push(Path::new(&std::env::var("HOME").unwrap()).join(".xargo").join("HOST").display().to_string());
150150
}
151151

152-
// we run the optimization passes inside miri
153-
// if we ran them twice we'd get funny failures due to borrowck ElaborateDrops only working on
154-
// unoptimized MIR
155-
// FIXME: add an after-mir-passes hook to rustc driver
156-
args.push("-Zmir-opt-level=0".to_owned());
152+
args.push("-Zmir-opt-level=3".to_owned());
157153
// for auxilary builds in unit tests
158154
args.push("-Zalways-encode-mir".to_owned());
159155

@@ -218,7 +214,7 @@ fn main() {
218214
}
219215
}
220216
}
221-
let stderr = std::io::stderr();:{MetaItemKind, NestedMetaItemKind, self};
217+
let stderr = std::io::stderr();
222218
let mut stderr = stderr.lock();
223219
writeln!(stderr, "{} success, {} no mir, {} crate not found, {} failed, \
224220
{} C fn, {} ABI, {} unsupported, {} intrinsic",

src/librustc_mir/interpret/eval_context.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
955955
let variant_def = adt_def.struct_variant();
956956
use rustc::ty::layout::Layout::*;
957957
match *self.type_layout(ty)? {
958+
UntaggedUnion { ref variants } =>
959+
Ok(TyAndPacked { ty: variant_def.fields[field_index].ty(self.tcx, substs), packed: variants.packed }),
958960
Univariant { ref variant, .. } =>
959961
Ok(TyAndPacked { ty: variant_def.fields[field_index].ty(self.tcx, substs), packed: variant.packed }),
960962
_ => Err(EvalError::Unimplemented(format!("get_field_ty can't handle struct type: {:?}, {:?}", ty, ty.sty))),
@@ -988,8 +990,9 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
988990
StructWrappedNullablePointer { ref nonnull, .. } => {
989991
Ok(nonnull.offsets[field_index])
990992
}
993+
UntaggedUnion { .. } => Ok(Size::from_bytes(0)),
991994
_ => {
992-
let msg = format!("can't handle type: {:?}, with layout: {:?}", ty, layout);
995+
let msg = format!("get_field_offset: can't handle type: {:?}, with layout: {:?}", ty, layout);
993996
Err(EvalError::Unimplemented(msg))
994997
}
995998
}
@@ -1006,8 +1009,9 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
10061009
Vector { count , .. } |
10071010
Array { count, .. } => Ok(count),
10081011
Scalar { .. } => Ok(0),
1012+
UntaggedUnion { .. } => Ok(1),
10091013
_ => {
1010-
let msg = format!("can't handle type: {:?}, with layout: {:?}", ty, layout);
1014+
let msg = format!("get_field_count: can't handle type: {:?}, with layout: {:?}", ty, layout);
10111015
Err(EvalError::Unimplemented(msg))
10121016
}
10131017
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(unsized_tuple_coercion)]
12+
13+
fn main() {
14+
let x : &(i32, i32, [i32]) = &(0, 1, [2, 3]);
15+
let y : &(i32, i32, [i32]) = &(0, 1, [2, 3, 4]);
16+
let mut a = [y, x];
17+
a.sort();
18+
assert_eq!(a, [x, y]);
19+
20+
assert_eq!(&format!("{:?}", a), "[(0, 1, [2, 3]), (0, 1, [2, 3, 4])]");
21+
}

0 commit comments

Comments
 (0)