Skip to content

Commit a8ebd08

Browse files
committed
Auto merge of #41529 - bitshifter:issue-41479, r=eddyb
Add missing OperandPair struct field index adjustments. Fixes #41479. This is a bug fix for a regression in 6d841da.
2 parents 94e884b + a510e1d commit a8ebd08

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/librustc_trans/mir/operand.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,15 @@ impl<'a, 'tcx> OperandRef<'tcx> {
8585
assert!(common::type_is_zero_size(ccx, ty));
8686
let llty = type_of::type_of(ccx, ty);
8787
let val = if common::type_is_imm_pair(ccx, ty) {
88+
let layout = ccx.layout_of(ty);
89+
let (ix0, ix1) = if let Layout::Univariant { ref variant, .. } = *layout {
90+
(adt::struct_llfields_index(variant, 0),
91+
adt::struct_llfields_index(variant, 1))
92+
} else {
93+
(0, 1)
94+
};
8895
let fields = llty.field_types();
89-
OperandValue::Pair(C_null(fields[0]), C_null(fields[1]))
96+
OperandValue::Pair(C_null(fields[ix0]), C_null(fields[ix1]))
9097
} else {
9198
OperandValue::Immediate(C_null(llty))
9299
};
@@ -156,8 +163,16 @@ impl<'a, 'tcx> OperandRef<'tcx> {
156163
if common::type_is_imm_pair(bcx.ccx, self.ty) {
157164
debug!("Operand::unpack_if_pair: unpacking {:?}", self);
158165

159-
let mut a = bcx.extract_value(llval, 0);
160-
let mut b = bcx.extract_value(llval, 1);
166+
let layout = bcx.ccx.layout_of(self.ty);
167+
let (ix0, ix1) = if let Layout::Univariant { ref variant, .. } = *layout {
168+
(adt::struct_llfields_index(variant, 0),
169+
adt::struct_llfields_index(variant, 1))
170+
} else {
171+
(0, 1)
172+
};
173+
174+
let mut a = bcx.extract_value(llval, ix0);
175+
let mut b = bcx.extract_value(llval, ix1);
161176

162177
let pair_fields = common::type_pair_fields(bcx.ccx, self.ty);
163178
if let Some([a_ty, b_ty]) = pair_fields {

src/test/run-pass/issue-41479.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
fn split<A, B>(pair: (A, B)) {
12+
let _a = pair.0;
13+
let _b = pair.1;
14+
}
15+
16+
fn main() {
17+
split(((), ((), ())));
18+
}

0 commit comments

Comments
 (0)