Skip to content

Commit 8b449c3

Browse files
authored
Merge pull request #284 from oli-obk/no_more_llvm_madness
Rust reorders fields, but miri uses the order from the source files
2 parents 726b027 + 181bb30 commit 8b449c3

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
690690
}
691691
}
692692

693-
StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
693+
StructWrappedNullablePointer { nndiscr, ref discrfield_source, .. } => {
694694
if let mir::AggregateKind::Adt(_, variant, _, _) = **kind {
695695
if nndiscr == variant as u64 {
696696
self.assign_fields(dest, dest_ty, operands)?;
@@ -699,7 +699,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
699699
let operand_ty = self.operand_ty(operand);
700700
assert_eq!(self.type_size(operand_ty)?, Some(0));
701701
}
702-
let (offset, TyAndPacked { ty, packed: _}) = self.nonnull_offset_and_ty(dest_ty, nndiscr, discrfield)?;
702+
let (offset, TyAndPacked { ty, packed: _}) = self.nonnull_offset_and_ty(dest_ty, nndiscr, discrfield_source)?;
703703
// TODO: The packed flag is ignored
704704

705705
// FIXME(solson)

src/librustc_mir/interpret/step.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
104104
}
105105
}
106106

107-
Layout::StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
107+
Layout::StructWrappedNullablePointer { nndiscr, ref discrfield_source, .. } => {
108108
if variant_index as u64 != nndiscr {
109-
let (offset, TyAndPacked { ty, packed }) = self.nonnull_offset_and_ty(dest_ty, nndiscr, discrfield)?;
109+
let (offset, TyAndPacked { ty, packed }) = self.nonnull_offset_and_ty(dest_ty, nndiscr, discrfield_source)?;
110110
let nonnull = self.force_allocation(dest)?.to_ptr()?.offset(offset.bytes(), &self)?;
111111
trace!("struct wrapped nullable pointer type: {}", ty);
112112
// only the pointer part of a fat pointer is used for this space optimization

src/librustc_mir/interpret/terminator/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
440440
self.read_nonnull_discriminant_value(adt_ptr, nndiscr as u128, discr_size)?
441441
}
442442

443-
StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
444-
let (offset, TyAndPacked { ty, packed }) = self.nonnull_offset_and_ty(adt_ty, nndiscr, discrfield)?;
443+
StructWrappedNullablePointer { nndiscr, ref discrfield_source, .. } => {
444+
let (offset, TyAndPacked { ty, packed }) = self.nonnull_offset_and_ty(adt_ty, nndiscr, discrfield_source)?;
445445
let nonnull = adt_ptr.offset(offset.bytes(), &*self)?;
446446
trace!("struct wrapped nullable pointer type: {}", ty);
447447
// only the pointer part of a fat pointer is used for this space optimization

tests/run-pass/issue-29746.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2015 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+
// zip!(a1,a2,a3,a4) is equivalent to:
12+
// a1.zip(a2).zip(a3).zip(a4).map(|(((x1,x2),x3),x4)| (x1,x2,x3,x4))
13+
macro_rules! zip {
14+
// Entry point
15+
([$a:expr, $b:expr, $($rest:expr),*]) => {
16+
zip!([$($rest),*], $a.zip($b), (x,y), [x,y])
17+
};
18+
19+
// Intermediate steps to build the zipped expression, the match pattern, and
20+
// and the output tuple of the closure, using macro hygene to repeatedly
21+
// introduce new variables named 'x'.
22+
([$a:expr, $($rest:expr),*], $zip:expr, $pat:pat, [$($flat:expr),*]) => {
23+
zip!([$($rest),*], $zip.zip($a), ($pat,x), [$($flat),*, x])
24+
};
25+
26+
// Final step
27+
([], $zip:expr, $pat:pat, [$($flat:expr),+]) => {
28+
$zip.map(|$pat| ($($flat),+))
29+
};
30+
31+
// Comma
32+
([$a:expr], $zip:expr, $pat:pat, [$($flat:expr),*]) => {
33+
zip!([$a,], $zip, $pat, [$($flat),*])
34+
};
35+
}
36+
37+
fn main() {
38+
let p1 = vec![1i32, 2].into_iter();
39+
let p2 = vec!["10", "20"].into_iter();
40+
let p3 = vec![100u16, 200].into_iter();
41+
let p4 = vec![1000i64, 2000].into_iter();
42+
43+
let e = zip!([p1,p2,p3,p4]).collect::<Vec<_>>();
44+
assert_eq!(e[0], (1i32,"10",100u16,1000i64));
45+
}

0 commit comments

Comments
 (0)