Skip to content

Commit 71ed31f

Browse files
committed
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
2 parents 3fd27b2 + 97228f5 commit 71ed31f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/librustc/ty/layout.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1655,10 +1655,10 @@ impl<'a, 'tcx> LayoutDetails {
16551655
discr,
16561656
variants
16571657
},
1658-
// FIXME(eddyb): using `FieldPlacement::Arbitrary` here results
1659-
// in lost optimizations, specifically around allocations, see
1660-
// `test/codegen/{alloc-optimisation,vec-optimizes-away}.rs`.
1661-
fields: FieldPlacement::Union(1),
1658+
fields: FieldPlacement::Arbitrary {
1659+
offsets: vec![Size::from_bytes(0)],
1660+
memory_index: vec![0]
1661+
},
16621662
abi,
16631663
align,
16641664
size

src/test/codegen/align-struct.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ pub enum Enum4 {
3232
A(i32),
3333
B(i32),
3434
}
35-
// CHECK: %Enum4 = type { [2 x i32] }
35+
// CHECK: %Enum4 = type { [0 x i32], i32, [1 x i32] }
36+
// CHECK: %"Enum4::A" = type { [1 x i32], i32, [0 x i32] }
3637

3738
pub enum Enum64 {
3839
A(Align64),
3940
B(i32),
4041
}
41-
// CHECK: %Enum64 = type { [16 x i64] }
42+
// CHECK: %Enum64 = type { [0 x i32], i32, [31 x i32] }
4243
// CHECK: %"Enum64::A" = type { [8 x i64], %Align64, [0 x i64] }
4344

4445
// CHECK-LABEL: @align64

0 commit comments

Comments
 (0)