Skip to content

Commit a380782

Browse files
committed
Merge from rustc
2 parents 19518a2 + 181aec7 commit a380782

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::num::*;
2+
3+
#[repr(C)]
4+
struct S1(NonZeroI32);
5+
6+
#[repr(C)]
7+
struct S2(i32);
8+
9+
fn callee(_s: S2) {}
10+
11+
fn main() {
12+
let fnptr: fn(S2) = callee;
13+
let fnptr: fn(S1) = unsafe { std::mem::transmute(fnptr) };
14+
fnptr(S1(NonZeroI32::new(1).unwrap()));
15+
//~^ ERROR: calling a function with argument of type S2 passing data of type S1
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: Undefined Behavior: calling a function with argument of type S2 passing data of type S1
2+
--> $DIR/abi_mismatch_repr_C.rs:LL:CC
3+
|
4+
LL | fnptr(S1(NonZeroI32::new(1).unwrap()));
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with argument of type S2 passing data of type S1
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= help: this means these two types are not *guaranteed* to be ABI-compatible across all targets
10+
= help: if you think this code should be accepted anyway, please report an issue
11+
= note: BACKTRACE:
12+
= note: inside `main` at $DIR/abi_mismatch_repr_C.rs:LL:CC
13+
14+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
15+
16+
error: aborting due to 1 previous error
17+

0 commit comments

Comments
 (0)