forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do not allow ABI mismatches inside repr(C) types
- Loading branch information
Showing
3 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/tools/miri/tests/fail/function_pointers/abi_mismatch_repr_C.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::num::*; | ||
|
||
#[repr(C)] | ||
struct S1(NonZeroI32); | ||
|
||
#[repr(C)] | ||
struct S2(i32); | ||
|
||
fn callee(_s: S2) {} | ||
|
||
fn main() { | ||
let fnptr: fn(S2) = callee; | ||
let fnptr: fn(S1) = unsafe { std::mem::transmute(fnptr) }; | ||
fnptr(S1(NonZeroI32::new(1).unwrap())); | ||
//~^ ERROR: calling a function with argument of type S2 passing data of type S1 | ||
} |
17 changes: 17 additions & 0 deletions
17
src/tools/miri/tests/fail/function_pointers/abi_mismatch_repr_C.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: Undefined Behavior: calling a function with argument of type S2 passing data of type S1 | ||
--> $DIR/abi_mismatch_repr_C.rs:LL:CC | ||
| | ||
LL | fnptr(S1(NonZeroI32::new(1).unwrap())); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with argument of type S2 passing data of type S1 | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= help: this means these two types are not *guaranteed* to be ABI-compatible across all targets | ||
= help: if you think this code should be accepted anyway, please report an issue | ||
= note: BACKTRACE: | ||
= note: inside `main` at $DIR/abi_mismatch_repr_C.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|