about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-12-27 10:19:43 +0000
committerbors <bors@rust-lang.org>2017-12-27 10:19:43 +0000
commit71ed31f24054863b807f68f244c6828ce6d2e516 (patch)
tree398510c60a4095ce0f185401880fa51e9ae173f9 /src
parent3fd27b2718438ceec6243869cde3edde7e5a904e (diff)
parent97228f5e7b0d6a0dc5c97fa73fa7ab096e4eb58d (diff)
downloadrust-71ed31f24054863b807f68f244c6828ce6d2e516.tar.gz
rust-71ed31f24054863b807f68f244c6828ce6d2e516.zip
Auto merge of #47007 - eddyb:issue-46897, r=arielb1
rustc: don't use union layouts for tagged union enums.

Fixes #46897, fixes #43517 (AFAICT from the testcases).
This PR doesn't add any testcases, we should try to at least get perf ones (cc @Mark-Simulacrum).
I couldn't find an example in those issues where the choice of LLVM array vs struct (with N identical fields) for padding filler types is still needed, *on top of* this change, to prevent excessive LLVM sinking.

r? @arielb1
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/layout.rs8
-rw-r--r--src/test/codegen/align-struct.rs5
2 files changed, 7 insertions, 6 deletions
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs
index bf76f6e7d1d..017b16e4126 100644
--- a/src/librustc/ty/layout.rs
+++ b/src/librustc/ty/layout.rs
@@ -1655,10 +1655,10 @@ impl<'a, 'tcx> LayoutDetails {
                         discr,
                         variants
                     },
-                    // FIXME(eddyb): using `FieldPlacement::Arbitrary` here results
-                    // in lost optimizations, specifically around allocations, see
-                    // `test/codegen/{alloc-optimisation,vec-optimizes-away}.rs`.
-                    fields: FieldPlacement::Union(1),
+                    fields: FieldPlacement::Arbitrary {
+                        offsets: vec![Size::from_bytes(0)],
+                        memory_index: vec![0]
+                    },
                     abi,
                     align,
                     size
diff --git a/src/test/codegen/align-struct.rs b/src/test/codegen/align-struct.rs
index 3b720dc30d3..ab9f5dda3a1 100644
--- a/src/test/codegen/align-struct.rs
+++ b/src/test/codegen/align-struct.rs
@@ -32,13 +32,14 @@ pub enum Enum4 {
     A(i32),
     B(i32),
 }
-// CHECK: %Enum4 = type { [2 x i32] }
+// CHECK: %Enum4 = type { [0 x i32], i32, [1 x i32] }
+// CHECK: %"Enum4::A" = type { [1 x i32], i32, [0 x i32] }
 
 pub enum Enum64 {
     A(Align64),
     B(i32),
 }
-// CHECK: %Enum64 = type { [16 x i64] }
+// CHECK: %Enum64 = type { [0 x i32], i32, [31 x i32] }
 // CHECK: %"Enum64::A" = type { [8 x i64], %Align64, [0 x i64] }
 
 // CHECK-LABEL: @align64