Skip to content

Commit 71ad503

Browse files
authored
Rollup merge of rust-lang#87742 - npmccallum:naked_ffi, r=Amanieu
Validate FFI-safety warnings on naked functions Test that FFI-safety warnings don't get accidentally dropped on naked functions. The big picture is that if you implement a naked function with the Rust ABI you'll get a warning. Further, if you implement a naked function with a standardized ABI, but use non-FFI-safe types you will still get a warning. rust-lang/rfcs#2774 rust-lang/rfcs#2972 cc ``````@joshtriplett`````` ``````@Amanieu`````` ``````@haraldh``````
2 parents 5b43960 + a96fd57 commit 71ad503

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
// only-x86_64
3+
#![feature(asm)]
4+
#![feature(naked_functions)]
5+
#![crate_type = "lib"]
6+
7+
#[naked]
8+
pub extern "C" fn naked(p: char) -> u128 {
9+
//~^ WARN uses type `char`
10+
//~| WARN uses type `u128`
11+
unsafe { asm!("", options(noreturn)); }
12+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
warning: `extern` fn uses type `char`, which is not FFI-safe
2+
--> $DIR/naked-functions-ffi.rs:8:28
3+
|
4+
LL | pub extern "C" fn naked(p: char) -> u128 {
5+
| ^^^^ not FFI-safe
6+
|
7+
= note: `#[warn(improper_ctypes_definitions)]` on by default
8+
= help: consider using `u32` or `libc::wchar_t` instead
9+
= note: the `char` type has no C equivalent
10+
11+
warning: `extern` fn uses type `u128`, which is not FFI-safe
12+
--> $DIR/naked-functions-ffi.rs:8:37
13+
|
14+
LL | pub extern "C" fn naked(p: char) -> u128 {
15+
| ^^^^ not FFI-safe
16+
|
17+
= note: 128-bit integers don't currently have a known stable ABI
18+
19+
warning: 2 warnings emitted
20+

0 commit comments

Comments
 (0)