Skip to content

Commit 17c6eae

Browse files
committed
Add test and change ub message wording
1 parent 701b194 commit 17c6eae

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
@@ -928,11 +928,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
928928
self.read_c_str_with_char_size(ptr, wchar_t.size, wchar_t.align.abi)
929929
}
930930

931-
/// Check that the ABI is what we expect.
932-
fn check_abi<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
931+
/// Check that the calling convention is what we expect.
932+
fn check_callconv<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
933933
if fn_abi.conv != exp_abi {
934934
throw_ub_format!(
935-
"calling a function with ABI {exp_abi} using caller ABI {}",
935+
"calling a function with calling convention {exp_abi} using caller calling convention {}",
936936
fn_abi.conv
937937
);
938938
}
@@ -968,7 +968,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
968968
exp_abi: Conv,
969969
link_name: Symbol,
970970
) -> InterpResult<'tcx, ()> {
971-
self.check_abi(abi, exp_abi)?;
971+
self.check_callconv(abi, exp_abi)?;
972972
if let Some((body, instance)) = self.eval_context_mut().lookup_exported_symbol(link_name)? {
973973
// If compiler-builtins is providing the symbol, then don't treat it as a clash.
974974
// 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)