]> git.lizzy.rs Git - rust.git/commitdiff
Allow niche-filling dataful variants to be represented as a ScalarPair
authorAnthony Ramine <n.oxyde@gmail.com>
Mon, 26 Mar 2018 14:26:03 +0000 (16:26 +0200)
committerAnthony Ramine <n.oxyde@gmail.com>
Mon, 26 Mar 2018 15:35:29 +0000 (17:35 +0200)
src/librustc/ty/layout.rs
src/test/codegen/function-arguments.rs

index 029dd6f1fb466662046c0cd0a2e1ec052771023b..5f9c305d92f04ec32860e064606b3cb541e19f7d 100644 (file)
@@ -1517,10 +1517,21 @@ enum StructKind {
                             let offset = st[i].fields.offset(field_index) + offset;
                             let size = st[i].size;
 
-                            let abi = if offset.bytes() == 0 && niche.value.size(dl) == size {
-                                Abi::Scalar(niche.clone())
-                            } else {
-                                Abi::Aggregate { sized: true }
+                            let abi = match st[i].abi {
+                                Abi::Scalar(_) => Abi::Scalar(niche.clone()),
+                                Abi::ScalarPair(ref first, ref second) => {
+                                    // We need to use scalar_unit to reset the
+                                    // valid range to the maximal one for that
+                                    // primitive, because only the niche is
+                                    // guaranteed to be initialised, not the
+                                    // other primitive.
+                                    if offset.bytes() == 0 {
+                                        Abi::ScalarPair(niche.clone(), scalar_unit(second.value))
+                                    } else {
+                                        Abi::ScalarPair(scalar_unit(first.value), niche.clone())
+                                    }
+                                }
+                                _ => Abi::Aggregate { sized: true },
                             };
 
                             return Ok(tcx.intern_layout(LayoutDetails {
index 0e98d3f9050a8194573bdf8a23ef43955bc97869..de302c69056f6b3d53892fe12d9308e31dfa0bc5 100644 (file)
@@ -133,6 +133,12 @@ pub fn trait_borrow(_: &Drop) {
 pub fn trait_box(_: Box<Drop>) {
 }
 
+// CHECK: { i8*, i8* } @trait_option(i8* noalias %x.0, i8* %x.1)
+#[no_mangle]
+pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
+  x
+}
+
 // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly %x.0, [[USIZE]] %x.1)
 #[no_mangle]
 pub fn return_slice(x: &[u16]) -> &[u16] {