forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#123043 - GoldsteinE:fix/repr-c-dead-branches, r=oli-obk Disable dead variant removal for `#[repr(C)]` enums. This prevents removing dead branches from a `#[repr(C)]` enum (they now get discriminants allocated as if they were inhabited). Implementation notes: ABI of something like ```rust #[repr(C)] enum Foo { Foo(!), } ``` is still `Uninhabited`, but its layout is now computed as if all the branches were inhabited. This seemed to me like a proper way to do it, especially given that ABI sanity check explicitly asserts that type-level uninhabitedness implies ABI uninhabitedness. This probably needs some sort of FCP (given that it changes `#[repr(C)]` layout, which is a stable guarantee), but I’m not sure how to call for one or which team is the most relevant. See rust-lang/unsafe-code-guidelines#500.
- Loading branch information
Showing
10 changed files
with
1,549 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
288 changes: 288 additions & 0 deletions
288
tests/ui/repr/repr-c-dead-variants.aarch64-unknown-linux-gnu.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,288 @@ | ||
error: layout_of(Univariant) = Layout { | ||
size: Size(4 bytes), | ||
align: AbiAndPrefAlign { | ||
abi: Align(4 bytes), | ||
pref: $SOME_ALIGN, | ||
}, | ||
abi: Uninhabited, | ||
fields: Arbitrary { | ||
offsets: [ | ||
Size(0 bytes), | ||
], | ||
memory_index: [ | ||
0, | ||
], | ||
}, | ||
largest_niche: Some( | ||
Niche { | ||
offset: Size(0 bytes), | ||
value: Int( | ||
I32, | ||
false, | ||
), | ||
valid_range: 0..=0, | ||
}, | ||
), | ||
variants: Multiple { | ||
tag: Initialized { | ||
value: Int( | ||
I32, | ||
false, | ||
), | ||
valid_range: 0..=0, | ||
}, | ||
tag_encoding: Direct, | ||
tag_field: 0, | ||
variants: [ | ||
Layout { | ||
size: Size(4 bytes), | ||
align: AbiAndPrefAlign { | ||
abi: Align(4 bytes), | ||
pref: $SOME_ALIGN, | ||
}, | ||
abi: Uninhabited, | ||
fields: Arbitrary { | ||
offsets: [ | ||
Size(4 bytes), | ||
], | ||
memory_index: [ | ||
0, | ||
], | ||
}, | ||
largest_niche: None, | ||
variants: Single { | ||
index: 0, | ||
}, | ||
max_repr_align: None, | ||
unadjusted_abi_align: Align(4 bytes), | ||
}, | ||
], | ||
}, | ||
max_repr_align: None, | ||
unadjusted_abi_align: Align(4 bytes), | ||
} | ||
--> $DIR/repr-c-dead-variants.rs:38:1 | ||
| | ||
LL | enum Univariant { | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: layout_of(TwoVariants) = Layout { | ||
size: Size(8 bytes), | ||
align: AbiAndPrefAlign { | ||
abi: Align(4 bytes), | ||
pref: $SOME_ALIGN, | ||
}, | ||
abi: ScalarPair( | ||
Initialized { | ||
value: Int( | ||
I32, | ||
false, | ||
), | ||
valid_range: 0..=1, | ||
}, | ||
Union { | ||
value: Int( | ||
I8, | ||
false, | ||
), | ||
}, | ||
), | ||
fields: Arbitrary { | ||
offsets: [ | ||
Size(0 bytes), | ||
], | ||
memory_index: [ | ||
0, | ||
], | ||
}, | ||
largest_niche: Some( | ||
Niche { | ||
offset: Size(0 bytes), | ||
value: Int( | ||
I32, | ||
false, | ||
), | ||
valid_range: 0..=1, | ||
}, | ||
), | ||
variants: Multiple { | ||
tag: Initialized { | ||
value: Int( | ||
I32, | ||
false, | ||
), | ||
valid_range: 0..=1, | ||
}, | ||
tag_encoding: Direct, | ||
tag_field: 0, | ||
variants: [ | ||
Layout { | ||
size: Size(4 bytes), | ||
align: AbiAndPrefAlign { | ||
abi: Align(4 bytes), | ||
pref: $SOME_ALIGN, | ||
}, | ||
abi: Uninhabited, | ||
fields: Arbitrary { | ||
offsets: [ | ||
Size(4 bytes), | ||
], | ||
memory_index: [ | ||
0, | ||
], | ||
}, | ||
largest_niche: None, | ||
variants: Single { | ||
index: 0, | ||
}, | ||
max_repr_align: None, | ||
unadjusted_abi_align: Align(4 bytes), | ||
}, | ||
Layout { | ||
size: Size(8 bytes), | ||
align: AbiAndPrefAlign { | ||
abi: Align(4 bytes), | ||
pref: $SOME_ALIGN, | ||
}, | ||
abi: ScalarPair( | ||
Initialized { | ||
value: Int( | ||
I32, | ||
false, | ||
), | ||
valid_range: 0..=1, | ||
}, | ||
Union { | ||
value: Int( | ||
I8, | ||
false, | ||
), | ||
}, | ||
), | ||
fields: Arbitrary { | ||
offsets: [ | ||
Size(4 bytes), | ||
], | ||
memory_index: [ | ||
0, | ||
], | ||
}, | ||
largest_niche: None, | ||
variants: Single { | ||
index: 1, | ||
}, | ||
max_repr_align: None, | ||
unadjusted_abi_align: Align(4 bytes), | ||
}, | ||
], | ||
}, | ||
max_repr_align: None, | ||
unadjusted_abi_align: Align(4 bytes), | ||
} | ||
--> $DIR/repr-c-dead-variants.rs:45:1 | ||
| | ||
LL | enum TwoVariants { | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: layout_of(DeadBranchHasOtherField) = Layout { | ||
size: Size(16 bytes), | ||
align: AbiAndPrefAlign { | ||
abi: Align(8 bytes), | ||
pref: $SOME_ALIGN, | ||
}, | ||
abi: Aggregate { | ||
sized: true, | ||
}, | ||
fields: Arbitrary { | ||
offsets: [ | ||
Size(0 bytes), | ||
], | ||
memory_index: [ | ||
0, | ||
], | ||
}, | ||
largest_niche: Some( | ||
Niche { | ||
offset: Size(0 bytes), | ||
value: Int( | ||
I32, | ||
false, | ||
), | ||
valid_range: 0..=1, | ||
}, | ||
), | ||
variants: Multiple { | ||
tag: Initialized { | ||
value: Int( | ||
I32, | ||
false, | ||
), | ||
valid_range: 0..=1, | ||
}, | ||
tag_encoding: Direct, | ||
tag_field: 0, | ||
variants: [ | ||
Layout { | ||
size: Size(16 bytes), | ||
align: AbiAndPrefAlign { | ||
abi: Align(8 bytes), | ||
pref: $SOME_ALIGN, | ||
}, | ||
abi: Uninhabited, | ||
fields: Arbitrary { | ||
offsets: [ | ||
Size(8 bytes), | ||
Size(8 bytes), | ||
], | ||
memory_index: [ | ||
0, | ||
1, | ||
], | ||
}, | ||
largest_niche: None, | ||
variants: Single { | ||
index: 0, | ||
}, | ||
max_repr_align: Some( | ||
Align(8 bytes), | ||
), | ||
unadjusted_abi_align: Align(8 bytes), | ||
}, | ||
Layout { | ||
size: Size(16 bytes), | ||
align: AbiAndPrefAlign { | ||
abi: Align(8 bytes), | ||
pref: $SOME_ALIGN, | ||
}, | ||
abi: Aggregate { | ||
sized: true, | ||
}, | ||
fields: Arbitrary { | ||
offsets: [ | ||
Size(8 bytes), | ||
], | ||
memory_index: [ | ||
0, | ||
], | ||
}, | ||
largest_niche: None, | ||
variants: Single { | ||
index: 1, | ||
}, | ||
max_repr_align: None, | ||
unadjusted_abi_align: Align(8 bytes), | ||
}, | ||
], | ||
}, | ||
max_repr_align: Some( | ||
Align(8 bytes), | ||
), | ||
unadjusted_abi_align: Align(8 bytes), | ||
} | ||
--> $DIR/repr-c-dead-variants.rs:57:1 | ||
| | ||
LL | enum DeadBranchHasOtherField { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
Oops, something went wrong.