Skip to content

Commit 4556daa

Browse files
committed
Auto merge of #1370 - samrat:add-scalar-size-test, r=RalfJung
Add test to verify that argument size mismatch throws UB Also, bump up `rust-version` Closes #1355
2 parents da940eb + 73f258c commit 4556daa

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14b15521c52549ebbb113173b4abecd124b5a823
1+
e83f7563495dbe2629b0cbc738afb0808c4482e1

tests/compile-fail/shim_arg_size.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(rustc_private)]
2+
3+
fn main() {
4+
extern "C" {
5+
// Use the wrong type(ie. not the pointer width) for the `size`
6+
// argument.
7+
#[cfg(target_pointer_width="64")]
8+
fn malloc(size: u32) -> *mut std::ffi::c_void;
9+
10+
#[cfg(target_pointer_width="32")]
11+
fn malloc(size: u16) -> *mut std::ffi::c_void;
12+
}
13+
14+
unsafe {
15+
let _p1 = malloc(42); //~ ERROR Undefined Behavior: scalar size mismatch
16+
};
17+
}

0 commit comments

Comments
 (0)