Skip to content

Commit

Permalink
Fix sizes of repr(C) enums on hexagon
Browse files Browse the repository at this point in the history
Enums on hexagon use a smallest size (but at least 1 byte) that fits all
the enumeration values. This is unlike many other ABIs where enums are
at least 32 bits.
  • Loading branch information
nagisa committed Feb 21, 2021
1 parent 3e826bb commit 7130e46
Show file tree
Hide file tree
Showing 3 changed files with 476 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Expand Up @@ -130,6 +130,7 @@ impl IntegerExt for Integer {

if repr.c() {
match &tcx.sess.target.arch[..] {
"hexagon" => min_from_extern = Some(I8),
// WARNING: the ARM EABI has two variants; the one corresponding
// to `at_least == I32` appears to be used on Linux and NetBSD,
// but some systems may use the variant corresponding to no
Expand Down
33 changes: 33 additions & 0 deletions src/test/ui/layout/hexagon-enum.rs
@@ -0,0 +1,33 @@
// compile-flags: --target hexagon-unknown-linux-musl
//
// Verify that the hexagon targets implement the repr(C) for enums correctly.
//
// See #82100
#![feature(never_type, rustc_attrs, type_alias_impl_trait, no_core, lang_items)]
#![crate_type = "lib"]
#![no_core]

#[lang="sized"]
trait Sized {}

#[rustc_layout(debug)]
#[repr(C)]
enum A { Apple } //~ ERROR: layout_of

#[rustc_layout(debug)]
#[repr(C)]
enum B { Banana = 255, } //~ ERROR: layout_of

#[rustc_layout(debug)]
#[repr(C)]
enum C { Chaenomeles = 256, } //~ ERROR: layout_of

#[rustc_layout(debug)]
#[repr(C)]
enum P { Peach = 0x1000_0000isize, } //~ ERROR: layout_of

const TANGERINE: usize = 0x8100_0000; // hack to get negative numbers without negation operator!

#[rustc_layout(debug)]
#[repr(C)]
enum T { Tangerine = TANGERINE as isize } //~ ERROR: layout_of

0 comments on commit 7130e46

Please sign in to comment.