Skip to content

Add test to verify that argument size mismatch throws UB #1370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14b15521c52549ebbb113173b4abecd124b5a823
e83f7563495dbe2629b0cbc738afb0808c4482e1
17 changes: 17 additions & 0 deletions tests/compile-fail/shim_arg_size.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![feature(rustc_private)]

fn main() {
extern "C" {
// Use the wrong type(ie. not the pointer width) for the `size`
// argument.
#[cfg(target_pointer_width="64")]
fn malloc(size: u32) -> *mut std::ffi::c_void;

#[cfg(target_pointer_width="32")]
fn malloc(size: u16) -> *mut std::ffi::c_void;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size: u16

How about size: u64? These cases test data_size < target_size, whereas we should test data_size != target_size.

}

unsafe {
let _p1 = malloc(42); //~ ERROR Undefined Behavior: scalar size mismatch
};
}