From 72acea0e80574556c8e6655c12229386669b955d Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Tue, 25 Apr 2017 20:24:33 +1000 Subject: [PATCH 1/2] Add missing struct field index adjustments. Some accesses in OperandPairs were missing. Fixes #41479. --- src/librustc_trans/mir/operand.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/librustc_trans/mir/operand.rs b/src/librustc_trans/mir/operand.rs index 6889b5064b649..8b7c7d9d37232 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 { From a510e1df76e8f141530ad9e6a0f5dfc5ad1933cf Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Tue, 25 Apr 2017 21:16:41 +1000 Subject: [PATCH 2/2] Added test for #41479 from @eddyb. --- src/test/run-pass/issue-41479.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/run-pass/issue-41479.rs diff --git a/src/test/run-pass/issue-41479.rs b/src/test/run-pass/issue-41479.rs new file mode 100644 index 0000000000000..cc97b3323cf33 --- /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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn split(pair: (A, B)) { + let _a = pair.0; + let _b = pair.1; +} + +fn main() { + split(((), ((), ()))); +}