Skip to content

Commit

Permalink
Rollup merge of rust-lang#41529 - bitshifter:issue-41479, r=eddyb
Browse files Browse the repository at this point in the history
Add missing OperandPair struct field index adjustments. Fixes rust-lang#41479.

This is a bug fix for a regression in rust-lang@6d841da.
  • Loading branch information
frewsxcv authored Apr 26, 2017
2 parents 56be42e + a510e1d commit e52d9af
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/librustc_trans/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,15 @@ impl<'a, 'tcx> OperandRef<'tcx> {
assert!(common::type_is_zero_size(ccx, ty));
let llty = type_of::type_of(ccx, ty);
let val = if common::type_is_imm_pair(ccx, ty) {
let layout = ccx.layout_of(ty);
let (ix0, ix1) = if let Layout::Univariant { ref variant, .. } = *layout {
(adt::struct_llfields_index(variant, 0),
adt::struct_llfields_index(variant, 1))
} else {
(0, 1)
};
let fields = llty.field_types();
OperandValue::Pair(C_null(fields[0]), C_null(fields[1]))
OperandValue::Pair(C_null(fields[ix0]), C_null(fields[ix1]))
} else {
OperandValue::Immediate(C_null(llty))
};
Expand Down Expand Up @@ -156,8 +163,16 @@ impl<'a, 'tcx> OperandRef<'tcx> {
if common::type_is_imm_pair(bcx.ccx, self.ty) {
debug!("Operand::unpack_if_pair: unpacking {:?}", self);

let mut a = bcx.extract_value(llval, 0);
let mut b = bcx.extract_value(llval, 1);
let layout = bcx.ccx.layout_of(self.ty);
let (ix0, ix1) = if let Layout::Univariant { ref variant, .. } = *layout {
(adt::struct_llfields_index(variant, 0),
adt::struct_llfields_index(variant, 1))
} else {
(0, 1)
};

let mut a = bcx.extract_value(llval, ix0);
let mut b = bcx.extract_value(llval, ix1);

let pair_fields = common::type_pair_fields(bcx.ccx, self.ty);
if let Some([a_ty, b_ty]) = pair_fields {
Expand Down
18 changes: 18 additions & 0 deletions src/test/run-pass/issue-41479.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn split<A, B>(pair: (A, B)) {
let _a = pair.0;
let _b = pair.1;
}

fn main() {
split(((), ((), ())));
}

0 comments on commit e52d9af

Please sign in to comment.