Skip to content

Commit 74d57a5

Browse files
committed
Add test and change ub message wording
1 parent bbde683 commit 74d57a5

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/tools/miri/src/helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,11 +916,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
916916
self.read_c_str_with_char_size(ptr, wchar_t.size, wchar_t.align.abi)
917917
}
918918

919-
/// Check that the ABI is what we expect.
920-
fn check_abi<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
919+
/// Check that the calling convention is what we expect.
920+
fn check_callconv<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
921921
if fn_abi.conv != exp_abi {
922922
throw_ub_format!(
923-
"calling a function with ABI {exp_abi} using caller ABI {}",
923+
"calling a function with calling convention {exp_abi} using caller calling convention {}",
924924
fn_abi.conv
925925
);
926926
}
@@ -956,7 +956,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
956956
exp_abi: Conv,
957957
link_name: Symbol,
958958
) -> InterpResult<'tcx, ()> {
959-
self.check_abi(abi, exp_abi)?;
959+
self.check_callconv(abi, exp_abi)?;
960960
if let Some((body, instance)) = self.eval_context_mut().lookup_exported_symbol(link_name)? {
961961
// If compiler-builtins is providing the symbol, then don't treat it as a clash.
962962
// We'll use our built-in implementation in `emulate_foreign_item_inner` for increased
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extern "Rust" {
2+
fn pipe(fds: *mut std::ffi::c_int) -> std::ffi::c_int;
3+
}
4+
5+
// Test the error for calling convention mismatch.
6+
fn main() {
7+
let mut fds = [-1, -1];
8+
let res = unsafe { pipe(fds.as_mut_ptr()) };
9+
//~^ ERROR: calling a function with calling convention C using caller calling convention Rust
10+
assert_eq!(res, 0);
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: calling a function with calling convention C using caller calling convention Rust
2+
--> tests/fail/shims/callconv_mismatch.rs:LL:CC
3+
|
4+
LL | let res = unsafe { pipe(fds.as_mut_ptr()) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention C using caller calling convention Rust
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+
= note: BACKTRACE:
10+
= note: inside `main` at tests/fail/shims/callconv_mismatch.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+

0 commit comments

Comments
 (0)