Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 50a2de2

Browse files
authoredFeb 22, 2021
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
+442
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,442 @@
1+
error: layout_of(A) = Layout {
2+
fields: Arbitrary {
3+
offsets: [
4+
Size {
5+
raw: 0,
6+
},
7+
],
8+
memory_index: [
9+
0,
10+
],
11+
},
12+
variants: Multiple {
13+
tag: Scalar {
14+
value: Int(
15+
I8,
16+
false,
17+
),
18+
valid_range: 0..=0,
19+
},
20+
tag_encoding: Direct,
21+
tag_field: 0,
22+
variants: [
23+
Layout {
24+
fields: Arbitrary {
25+
offsets: [],
26+
memory_index: [],
27+
},
28+
variants: Single {
29+
index: 0,
30+
},
31+
abi: Aggregate {
32+
sized: true,
33+
},
34+
largest_niche: None,
35+
align: AbiAndPrefAlign {
36+
abi: Align {
37+
pow2: 0,
38+
},
39+
pref: Align {
40+
pow2: 0,
41+
},
42+
},
43+
size: Size {
44+
raw: 1,
45+
},
46+
},
47+
],
48+
},
49+
abi: Scalar(
50+
Scalar {
51+
value: Int(
52+
I8,
53+
false,
54+
),
55+
valid_range: 0..=0,
56+
},
57+
),
58+
largest_niche: Some(
59+
Niche {
60+
offset: Size {
61+
raw: 0,
62+
},
63+
scalar: Scalar {
64+
value: Int(
65+
I8,
66+
false,
67+
),
68+
valid_range: 0..=0,
69+
},
70+
},
71+
),
72+
align: AbiAndPrefAlign {
73+
abi: Align {
74+
pow2: 0,
75+
},
76+
pref: Align {
77+
pow2: 0,
78+
},
79+
},
80+
size: Size {
81+
raw: 1,
82+
},
83+
}
84+
--> $DIR/hexagon-enum.rs:15:1
85+
|
86+
LL | enum A { Apple }
87+
| ^^^^^^^^^^^^^^^^
88+
89+
error: layout_of(B) = Layout {
90+
fields: Arbitrary {
91+
offsets: [
92+
Size {
93+
raw: 0,
94+
},
95+
],
96+
memory_index: [
97+
0,
98+
],
99+
},
100+
variants: Multiple {
101+
tag: Scalar {
102+
value: Int(
103+
I8,
104+
false,
105+
),
106+
valid_range: 255..=255,
107+
},
108+
tag_encoding: Direct,
109+
tag_field: 0,
110+
variants: [
111+
Layout {
112+
fields: Arbitrary {
113+
offsets: [],
114+
memory_index: [],
115+
},
116+
variants: Single {
117+
index: 0,
118+
},
119+
abi: Aggregate {
120+
sized: true,
121+
},
122+
largest_niche: None,
123+
align: AbiAndPrefAlign {
124+
abi: Align {
125+
pow2: 0,
126+
},
127+
pref: Align {
128+
pow2: 0,
129+
},
130+
},
131+
size: Size {
132+
raw: 1,
133+
},
134+
},
135+
],
136+
},
137+
abi: Scalar(
138+
Scalar {
139+
value: Int(
140+
I8,
141+
false,
142+
),
143+
valid_range: 255..=255,
144+
},
145+
),
146+
largest_niche: Some(
147+
Niche {
148+
offset: Size {
149+
raw: 0,
150+
},
151+
scalar: Scalar {
152+
value: Int(
153+
I8,
154+
false,
155+
),
156+
valid_range: 255..=255,
157+
},
158+
},
159+
),
160+
align: AbiAndPrefAlign {
161+
abi: Align {
162+
pow2: 0,
163+
},
164+
pref: Align {
165+
pow2: 0,
166+
},
167+
},
168+
size: Size {
169+
raw: 1,
170+
},
171+
}
172+
--> $DIR/hexagon-enum.rs:19:1
173+
|
174+
LL | enum B { Banana = 255, }
175+
| ^^^^^^^^^^^^^^^^^^^^^^^^
176+
177+
error: layout_of(C) = Layout {
178+
fields: Arbitrary {
179+
offsets: [
180+
Size {
181+
raw: 0,
182+
},
183+
],
184+
memory_index: [
185+
0,
186+
],
187+
},
188+
variants: Multiple {
189+
tag: Scalar {
190+
value: Int(
191+
I16,
192+
false,
193+
),
194+
valid_range: 256..=256,
195+
},
196+
tag_encoding: Direct,
197+
tag_field: 0,
198+
variants: [
199+
Layout {
200+
fields: Arbitrary {
201+
offsets: [],
202+
memory_index: [],
203+
},
204+
variants: Single {
205+
index: 0,
206+
},
207+
abi: Aggregate {
208+
sized: true,
209+
},
210+
largest_niche: None,
211+
align: AbiAndPrefAlign {
212+
abi: Align {
213+
pow2: 1,
214+
},
215+
pref: Align {
216+
pow2: 1,
217+
},
218+
},
219+
size: Size {
220+
raw: 2,
221+
},
222+
},
223+
],
224+
},
225+
abi: Scalar(
226+
Scalar {
227+
value: Int(
228+
I16,
229+
false,
230+
),
231+
valid_range: 256..=256,
232+
},
233+
),
234+
largest_niche: Some(
235+
Niche {
236+
offset: Size {
237+
raw: 0,
238+
},
239+
scalar: Scalar {
240+
value: Int(
241+
I16,
242+
false,
243+
),
244+
valid_range: 256..=256,
245+
},
246+
},
247+
),
248+
align: AbiAndPrefAlign {
249+
abi: Align {
250+
pow2: 1,
251+
},
252+
pref: Align {
253+
pow2: 1,
254+
},
255+
},
256+
size: Size {
257+
raw: 2,
258+
},
259+
}
260+
--> $DIR/hexagon-enum.rs:23:1
261+
|
262+
LL | enum C { Chaenomeles = 256, }
263+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
264+
265+
error: layout_of(P) = Layout {
266+
fields: Arbitrary {
267+
offsets: [
268+
Size {
269+
raw: 0,
270+
},
271+
],
272+
memory_index: [
273+
0,
274+
],
275+
},
276+
variants: Multiple {
277+
tag: Scalar {
278+
value: Int(
279+
I32,
280+
false,
281+
),
282+
valid_range: 268435456..=268435456,
283+
},
284+
tag_encoding: Direct,
285+
tag_field: 0,
286+
variants: [
287+
Layout {
288+
fields: Arbitrary {
289+
offsets: [],
290+
memory_index: [],
291+
},
292+
variants: Single {
293+
index: 0,
294+
},
295+
abi: Aggregate {
296+
sized: true,
297+
},
298+
largest_niche: None,
299+
align: AbiAndPrefAlign {
300+
abi: Align {
301+
pow2: 2,
302+
},
303+
pref: Align {
304+
pow2: 2,
305+
},
306+
},
307+
size: Size {
308+
raw: 4,
309+
},
310+
},
311+
],
312+
},
313+
abi: Scalar(
314+
Scalar {
315+
value: Int(
316+
I32,
317+
false,
318+
),
319+
valid_range: 268435456..=268435456,
320+
},
321+
),
322+
largest_niche: Some(
323+
Niche {
324+
offset: Size {
325+
raw: 0,
326+
},
327+
scalar: Scalar {
328+
value: Int(
329+
I32,
330+
false,
331+
),
332+
valid_range: 268435456..=268435456,
333+
},
334+
},
335+
),
336+
align: AbiAndPrefAlign {
337+
abi: Align {
338+
pow2: 2,
339+
},
340+
pref: Align {
341+
pow2: 2,
342+
},
343+
},
344+
size: Size {
345+
raw: 4,
346+
},
347+
}
348+
--> $DIR/hexagon-enum.rs:27:1
349+
|
350+
LL | enum P { Peach = 0x1000_0000isize, }
351+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
352+
353+
error: layout_of(T) = Layout {
354+
fields: Arbitrary {
355+
offsets: [
356+
Size {
357+
raw: 0,
358+
},
359+
],
360+
memory_index: [
361+
0,
362+
],
363+
},
364+
variants: Multiple {
365+
tag: Scalar {
366+
value: Int(
367+
I32,
368+
true,
369+
),
370+
valid_range: 2164260864..=2164260864,
371+
},
372+
tag_encoding: Direct,
373+
tag_field: 0,
374+
variants: [
375+
Layout {
376+
fields: Arbitrary {
377+
offsets: [],
378+
memory_index: [],
379+
},
380+
variants: Single {
381+
index: 0,
382+
},
383+
abi: Aggregate {
384+
sized: true,
385+
},
386+
largest_niche: None,
387+
align: AbiAndPrefAlign {
388+
abi: Align {
389+
pow2: 2,
390+
},
391+
pref: Align {
392+
pow2: 2,
393+
},
394+
},
395+
size: Size {
396+
raw: 4,
397+
},
398+
},
399+
],
400+
},
401+
abi: Scalar(
402+
Scalar {
403+
value: Int(
404+
I32,
405+
true,
406+
),
407+
valid_range: 2164260864..=2164260864,
408+
},
409+
),
410+
largest_niche: Some(
411+
Niche {
412+
offset: Size {
413+
raw: 0,
414+
},
415+
scalar: Scalar {
416+
value: Int(
417+
I32,
418+
true,
419+
),
420+
valid_range: 2164260864..=2164260864,
421+
},
422+
},
423+
),
424+
align: AbiAndPrefAlign {
425+
abi: Align {
426+
pow2: 2,
427+
},
428+
pref: Align {
429+
pow2: 2,
430+
},
431+
},
432+
size: Size {
433+
raw: 4,
434+
},
435+
}
436+
--> $DIR/hexagon-enum.rs:33:1
437+
|
438+
LL | enum T { Tangerine = TANGERINE as isize }
439+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
440+
441+
error: aborting due to 5 previous errors
442+

0 commit comments

Comments
 (0)
Please sign in to comment.