diff options
| author | tiif <pekyuan@gmail.com> | 2025-02-03 13:50:39 +0000 |
|---|---|---|
| committer | tiif <pekyuan@gmail.com> | 2025-03-12 14:38:51 +0000 |
| commit | 17c6eae2910ffcb0e2a285625984f2eded45a285 (patch) | |
| tree | 2ef7eed1b6ed02975131173d0f7cad1219e27486 | |
| parent | 701b1948abd46425ab588108bb406b7519ec16fa (diff) | |
| download | rust-17c6eae2910ffcb0e2a285625984f2eded45a285.tar.gz rust-17c6eae2910ffcb0e2a285625984f2eded45a285.zip | |
Add test and change ub message wording
| -rw-r--r-- | src/tools/miri/src/helpers.rs | 8 | ||||
| -rw-r--r-- | src/tools/miri/tests/fail/shims/callconv_mismatch.rs | 11 | ||||
| -rw-r--r-- | src/tools/miri/tests/fail/shims/callconv_mismatch.stderr | 15 |
3 files changed, 30 insertions, 4 deletions
diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index bf08f9639c0..04829a9424c 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -928,11 +928,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { self.read_c_str_with_char_size(ptr, wchar_t.size, wchar_t.align.abi) } - /// Check that the ABI is what we expect. - fn check_abi<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> { + /// Check that the calling convention is what we expect. + fn check_callconv<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> { if fn_abi.conv != exp_abi { throw_ub_format!( - "calling a function with ABI {exp_abi} using caller ABI {}", + "calling a function with calling convention {exp_abi} using caller calling convention {}", fn_abi.conv ); } @@ -968,7 +968,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { exp_abi: Conv, link_name: Symbol, ) -> InterpResult<'tcx, ()> { - self.check_abi(abi, exp_abi)?; + self.check_callconv(abi, exp_abi)?; if let Some((body, instance)) = self.eval_context_mut().lookup_exported_symbol(link_name)? { // If compiler-builtins is providing the symbol, then don't treat it as a clash. // We'll use our built-in implementation in `emulate_foreign_item_inner` for increased diff --git a/src/tools/miri/tests/fail/shims/callconv_mismatch.rs b/src/tools/miri/tests/fail/shims/callconv_mismatch.rs new file mode 100644 index 00000000000..2f9b89ae08d --- /dev/null +++ b/src/tools/miri/tests/fail/shims/callconv_mismatch.rs @@ -0,0 +1,11 @@ +extern "Rust" { + fn pipe(fds: *mut std::ffi::c_int) -> std::ffi::c_int; +} + +// Test the error for calling convention mismatch. +fn main() { + let mut fds = [-1, -1]; + let res = unsafe { pipe(fds.as_mut_ptr()) }; + //~^ ERROR: calling a function with calling convention C using caller calling convention Rust + assert_eq!(res, 0); +} \ No newline at end of file diff --git a/src/tools/miri/tests/fail/shims/callconv_mismatch.stderr b/src/tools/miri/tests/fail/shims/callconv_mismatch.stderr new file mode 100644 index 00000000000..11b57de1953 --- /dev/null +++ b/src/tools/miri/tests/fail/shims/callconv_mismatch.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: calling a function with calling convention C using caller calling convention Rust + --> tests/fail/shims/callconv_mismatch.rs:LL:CC + | +LL | let res = unsafe { pipe(fds.as_mut_ptr()) }; + | ^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention C using caller calling convention Rust + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at tests/fail/shims/callconv_mismatch.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error + |
