add uitest for naked functions and the repr attr on functions

This commit is contained in:
jdonszelmann 2024-08-27 16:46:39 +02:00
parent c3000ad3ba
commit a507ec644c
No known key found for this signature in database
GPG Key ID: E0C1EA36407B2FF2
2 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,48 @@
//@ needs-asm-support
#![feature(naked_functions)]
#![feature(fn_align)]
#![crate_type = "lib"]
use std::arch::asm;
#[repr(C)]
//~^ ERROR attribute should be applied to a struct, enum, or union [E0517]
#[naked]
extern "C" fn example1() {
//~^ NOTE not a struct, enum, or union
unsafe { asm!("", options(noreturn)) }
}
#[repr(transparent)]
//~^ ERROR attribute should be applied to a struct, enum, or union [E0517]
#[naked]
extern "C" fn example2() {
//~^ NOTE not a struct, enum, or union
unsafe { asm!("", options(noreturn)) }
}
#[repr(align(16), C)]
//~^ ERROR attribute should be applied to a struct, enum, or union [E0517]
#[naked]
extern "C" fn example3() {
//~^ NOTE not a struct, enum, or union
unsafe { asm!("", options(noreturn)) }
}
// note: two errors because of packed and C
#[repr(C, packed)]
//~^ ERROR attribute should be applied to a struct or union [E0517]
//~| ERROR attribute should be applied to a struct, enum, or union [E0517]
#[naked]
extern "C" fn example4() {
//~^ NOTE not a struct, enum, or union
//~| NOTE not a struct or union
unsafe { asm!("", options(noreturn)) }
}
#[repr(u8)]
//~^ ERROR attribute should be applied to an enum [E0517]
#[naked]
extern "C" fn example5() {
//~^ NOTE not an enum
unsafe { asm!("", options(noreturn)) }
}

View File

@ -0,0 +1,77 @@
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/naked-with-invalid-repr-attr.rs:7:8
|
LL | #[repr(C)]
| ^
...
LL | / extern "C" fn example1() {
LL | |
LL | | unsafe { asm!("", options(noreturn)) }
LL | | }
| |_- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/naked-with-invalid-repr-attr.rs:15:8
|
LL | #[repr(transparent)]
| ^^^^^^^^^^^
...
LL | / extern "C" fn example2() {
LL | |
LL | | unsafe { asm!("", options(noreturn)) }
LL | | }
| |_- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/naked-with-invalid-repr-attr.rs:23:19
|
LL | #[repr(align(16), C)]
| ^
...
LL | / extern "C" fn example3() {
LL | |
LL | | unsafe { asm!("", options(noreturn)) }
LL | | }
| |_- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/naked-with-invalid-repr-attr.rs:32:8
|
LL | #[repr(C, packed)]
| ^
...
LL | / extern "C" fn example4() {
LL | |
LL | |
LL | | unsafe { asm!("", options(noreturn)) }
LL | | }
| |_- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct or union
--> $DIR/naked-with-invalid-repr-attr.rs:32:11
|
LL | #[repr(C, packed)]
| ^^^^^^
...
LL | / extern "C" fn example4() {
LL | |
LL | |
LL | | unsafe { asm!("", options(noreturn)) }
LL | | }
| |_- not a struct or union
error[E0517]: attribute should be applied to an enum
--> $DIR/naked-with-invalid-repr-attr.rs:42:8
|
LL | #[repr(u8)]
| ^^
...
LL | / extern "C" fn example5() {
LL | |
LL | | unsafe { asm!("", options(noreturn)) }
LL | | }
| |_- not an enum
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0517`.