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 728a1f7

Browse files
authoredAug 28, 2024
Unrolled build for rust-lang#129421
Rollup merge of rust-lang#129421 - jdonszelmann:naked-repr-align-functions, r=workingjubilee,compiler-errors add repr to the allowlist for naked functions Fixes rust-lang#129412 (combining unstable features rust-lang#90957 (`#![feature(naked_functions)]`) and rust-lang#82232 (`#![feature(fn_align)]`)
2 parents ac77e88 + a507ec6 commit 728a1f7

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed
 

‎compiler/rustc_passes/src/check_attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
517517
sym::no_mangle,
518518
sym::naked,
519519
sym::instruction_set,
520+
sym::repr,
520521
// code generation
521522
sym::cold,
522523
sym::target_feature,

‎tests/codegen/naked-fn/aligned.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
2+
//@ needs-asm-support
3+
//@ ignore-arm no "ret" mnemonic
4+
5+
#![crate_type = "lib"]
6+
#![feature(naked_functions, fn_align)]
7+
use std::arch::asm;
8+
9+
// CHECK: Function Attrs: naked
10+
// CHECK-NEXT: define{{.*}}void @naked_empty()
11+
// CHECK: align 16
12+
#[repr(align(16))]
13+
#[no_mangle]
14+
#[naked]
15+
pub unsafe extern "C" fn naked_empty() {
16+
// CHECK-NEXT: start:
17+
// CHECK-NEXT: call void asm
18+
// CHECK-NEXT: unreachable
19+
asm!("ret", options(noreturn));
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//@ needs-asm-support
2+
#![feature(naked_functions)]
3+
#![feature(fn_align)]
4+
#![crate_type = "lib"]
5+
use std::arch::asm;
6+
7+
#[repr(C)]
8+
//~^ ERROR attribute should be applied to a struct, enum, or union [E0517]
9+
#[naked]
10+
extern "C" fn example1() {
11+
//~^ NOTE not a struct, enum, or union
12+
unsafe { asm!("", options(noreturn)) }
13+
}
14+
15+
#[repr(transparent)]
16+
//~^ ERROR attribute should be applied to a struct, enum, or union [E0517]
17+
#[naked]
18+
extern "C" fn example2() {
19+
//~^ NOTE not a struct, enum, or union
20+
unsafe { asm!("", options(noreturn)) }
21+
}
22+
23+
#[repr(align(16), C)]
24+
//~^ ERROR attribute should be applied to a struct, enum, or union [E0517]
25+
#[naked]
26+
extern "C" fn example3() {
27+
//~^ NOTE not a struct, enum, or union
28+
unsafe { asm!("", options(noreturn)) }
29+
}
30+
31+
// note: two errors because of packed and C
32+
#[repr(C, packed)]
33+
//~^ ERROR attribute should be applied to a struct or union [E0517]
34+
//~| ERROR attribute should be applied to a struct, enum, or union [E0517]
35+
#[naked]
36+
extern "C" fn example4() {
37+
//~^ NOTE not a struct, enum, or union
38+
//~| NOTE not a struct or union
39+
unsafe { asm!("", options(noreturn)) }
40+
}
41+
42+
#[repr(u8)]
43+
//~^ ERROR attribute should be applied to an enum [E0517]
44+
#[naked]
45+
extern "C" fn example5() {
46+
//~^ NOTE not an enum
47+
unsafe { asm!("", options(noreturn)) }
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
error[E0517]: attribute should be applied to a struct, enum, or union
2+
--> $DIR/naked-with-invalid-repr-attr.rs:7:8
3+
|
4+
LL | #[repr(C)]
5+
| ^
6+
...
7+
LL | / extern "C" fn example1() {
8+
LL | |
9+
LL | | unsafe { asm!("", options(noreturn)) }
10+
LL | | }
11+
| |_- not a struct, enum, or union
12+
13+
error[E0517]: attribute should be applied to a struct, enum, or union
14+
--> $DIR/naked-with-invalid-repr-attr.rs:15:8
15+
|
16+
LL | #[repr(transparent)]
17+
| ^^^^^^^^^^^
18+
...
19+
LL | / extern "C" fn example2() {
20+
LL | |
21+
LL | | unsafe { asm!("", options(noreturn)) }
22+
LL | | }
23+
| |_- not a struct, enum, or union
24+
25+
error[E0517]: attribute should be applied to a struct, enum, or union
26+
--> $DIR/naked-with-invalid-repr-attr.rs:23:19
27+
|
28+
LL | #[repr(align(16), C)]
29+
| ^
30+
...
31+
LL | / extern "C" fn example3() {
32+
LL | |
33+
LL | | unsafe { asm!("", options(noreturn)) }
34+
LL | | }
35+
| |_- not a struct, enum, or union
36+
37+
error[E0517]: attribute should be applied to a struct, enum, or union
38+
--> $DIR/naked-with-invalid-repr-attr.rs:32:8
39+
|
40+
LL | #[repr(C, packed)]
41+
| ^
42+
...
43+
LL | / extern "C" fn example4() {
44+
LL | |
45+
LL | |
46+
LL | | unsafe { asm!("", options(noreturn)) }
47+
LL | | }
48+
| |_- not a struct, enum, or union
49+
50+
error[E0517]: attribute should be applied to a struct or union
51+
--> $DIR/naked-with-invalid-repr-attr.rs:32:11
52+
|
53+
LL | #[repr(C, packed)]
54+
| ^^^^^^
55+
...
56+
LL | / extern "C" fn example4() {
57+
LL | |
58+
LL | |
59+
LL | | unsafe { asm!("", options(noreturn)) }
60+
LL | | }
61+
| |_- not a struct or union
62+
63+
error[E0517]: attribute should be applied to an enum
64+
--> $DIR/naked-with-invalid-repr-attr.rs:42:8
65+
|
66+
LL | #[repr(u8)]
67+
| ^^
68+
...
69+
LL | / extern "C" fn example5() {
70+
LL | |
71+
LL | | unsafe { asm!("", options(noreturn)) }
72+
LL | | }
73+
| |_- not an enum
74+
75+
error: aborting due to 6 previous errors
76+
77+
For more information about this error, try `rustc --explain E0517`.

0 commit comments

Comments
 (0)
Failed to load comments.