Skip to content

Commit 50a2de2

Browse files
authored
Rollup merge of #82379 - nagisa:nagisa/hexagon-enums, r=estebank
Fix sizes of repr(C) enums on hexagon 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. Fixes #82100
2 parents 7958166 + 7130e46 commit 50a2de2

File tree

3 files changed

+476
-0
lines changed

3 files changed

+476
-0
lines changed

compiler/rustc_middle/src/ty/layout.rs

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl IntegerExt for Integer {
130130

131131
if repr.c() {
132132
match &tcx.sess.target.arch[..] {
133+
"hexagon" => min_from_extern = Some(I8),
133134
// WARNING: the ARM EABI has two variants; the one corresponding
134135
// to `at_least == I32` appears to be used on Linux and NetBSD,
135136
// but some systems may use the variant corresponding to no

src/test/ui/layout/hexagon-enum.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// compile-flags: --target hexagon-unknown-linux-musl
2+
//
3+
// Verify that the hexagon targets implement the repr(C) for enums correctly.
4+
//
5+
// See #82100
6+
#![feature(never_type, rustc_attrs, type_alias_impl_trait, no_core, lang_items)]
7+
#![crate_type = "lib"]
8+
#![no_core]
9+
10+
#[lang="sized"]
11+
trait Sized {}
12+
13+
#[rustc_layout(debug)]
14+
#[repr(C)]
15+
enum A { Apple } //~ ERROR: layout_of
16+
17+
#[rustc_layout(debug)]
18+
#[repr(C)]
19+
enum B { Banana = 255, } //~ ERROR: layout_of
20+
21+
#[rustc_layout(debug)]
22+
#[repr(C)]
23+
enum C { Chaenomeles = 256, } //~ ERROR: layout_of
24+
25+
#[rustc_layout(debug)]
26+
#[repr(C)]
27+
enum P { Peach = 0x1000_0000isize, } //~ ERROR: layout_of
28+
29+
const TANGERINE: usize = 0x8100_0000; // hack to get negative numbers without negation operator!
30+
31+
#[rustc_layout(debug)]
32+
#[repr(C)]
33+
enum T { Tangerine = TANGERINE as isize } //~ ERROR: layout_of

0 commit comments

Comments
 (0)