Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary fix for the layout of aligned enums #92932

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
},
};
let mut abi = Abi::Aggregate { sized: true };
if tag.value.size(dl) == size {

// Without latter check aligned enums with custom discriminant values
// Would result in ICE see the issue #92464 for more info
if tag.value.size(dl) == size || variants.iter().all(|layout| layout.is_empty()) {
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
abi = Abi::Scalar(tag);
} else {
// Try to use a ScalarPair for all tagged enums.
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/aligned_enum_cast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// run-pass
// allows aligned custom discriminant enums to cast into other types
// See the issue #92464 for more info
#[allow(dead_code)]
#[repr(align(8))]
enum Aligned {
Zero = 0,
One = 1,
}

fn main() {
let aligned = Aligned::Zero;
let fo = aligned as u8;
println!("foo {}",fo);
}