diff options
| author | bors <bors@rust-lang.org> | 2017-04-27 21:54:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-04-27 21:54:07 +0000 |
| commit | a8ebd083fcc7120f8fffffa061525bb225a3e17b (patch) | |
| tree | 4bddb7e1094b65698573e93e1d8c52d2c30ae79f /src | |
| parent | 94e884b6307a59f1e6e64aa7ebc1996b651a7629 (diff) | |
| parent | a510e1df76e8f141530ad9e6a0f5dfc5ad1933cf (diff) | |
| download | rust-a8ebd083fcc7120f8fffffa061525bb225a3e17b.tar.gz rust-a8ebd083fcc7120f8fffffa061525bb225a3e17b.zip | |
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 https://github.com/rust-lang/rust/commit/6d841da4a0d7629f826117f99052e3d4a7997a7e.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_trans/mir/operand.rs | 21 | ||||
| -rw-r--r-- | src/test/run-pass/issue-41479.rs | 18 |
2 files changed, 36 insertions, 3 deletions
diff --git a/src/librustc_trans/mir/operand.rs b/src/librustc_trans/mir/operand.rs index 6889b5064b6..8b7c7d9d372 100644 --- a/src/librustc_trans/mir/operand.rs +++ b/src/librustc_trans/mir/operand.rs @@ -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)) }; @@ -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 { diff --git a/src/test/run-pass/issue-41479.rs b/src/test/run-pass/issue-41479.rs new file mode 100644 index 00000000000..cc97b3323cf --- /dev/null +++ b/src/test/run-pass/issue-41479.rs @@ -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(((), ((), ()))); +} |
