Skip to content

Commit 838c423

Browse files
committed
Auto merge of #115182 - RalfJung:abi-compat-sign, r=b-naber
miri ABI compatibility check: accept u32 and i32 If only the sign differs, then surely these types are compatible. (We do still check that `arg_ext` is the same, just in case.) Also I made it so that the ABI check must *imply* that size and alignment are the same, but it doesn't actively check that itself. With how crazy ABI constraints get, having equal size and align really shouldn't be used as a signal for anything I think...
2 parents 98b55eb + 1b71397 commit 838c423

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::num;
2+
use std::mem;
3+
4+
fn test_abi_compat<T, U>(t: T, u: U) {
5+
fn id<T>(x: T) -> T { x }
6+
7+
// This checks ABI compatibility both for arguments and return values,
8+
// in both directions.
9+
let f: fn(T) -> T = id;
10+
let f: fn(U) -> U = unsafe { std::mem::transmute(f) };
11+
drop(f(u));
12+
13+
let f: fn(U) -> U = id;
14+
let f: fn(T) -> T = unsafe { std::mem::transmute(f) };
15+
drop(f(t));
16+
}
17+
18+
fn main() {
19+
test_abi_compat(0u32, 'x');
20+
test_abi_compat(&0u32, &([true; 4], [0u32; 0]));
21+
test_abi_compat(0u32, mem::MaybeUninit::new(0u32));
22+
test_abi_compat(42u32, num::NonZeroU32::new(1).unwrap());
23+
test_abi_compat(0u32, Some(num::NonZeroU32::new(1).unwrap()));
24+
test_abi_compat(0u32, 0i32);
25+
// Note that `bool` and `u8` are *not* compatible!
26+
// One of them has `arg_ext: Zext`, the other does not.
27+
}

0 commit comments

Comments
 (0)