about summary refs log tree commit diff
path: root/src/librustc_trans
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-04-27 21:54:07 +0000
committerbors <bors@rust-lang.org>2017-04-27 21:54:07 +0000
commita8ebd083fcc7120f8fffffa061525bb225a3e17b (patch)
tree4bddb7e1094b65698573e93e1d8c52d2c30ae79f /src/librustc_trans
parent94e884b6307a59f1e6e64aa7ebc1996b651a7629 (diff)
parenta510e1df76e8f141530ad9e6a0f5dfc5ad1933cf (diff)
downloadrust-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/librustc_trans')
-rw-r--r--src/librustc_trans/mir/operand.rs21
1 files changed, 18 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 {