![](/style/images/good.png)
![](/style/images/bad.png)
Github Improve error message of calling unsupported non-"C"/"syst...
source link: https://github.com/rust-lang/miri/pull/1745
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Miri currently reports the following foo()
call has ABI-mismatch UB:
#[cfg(unix)] extern "Rust" { // or any non-"C" ABI fn foo(); } #[cfg(windows)] extern "C" { // or any non-"system" ABI fn foo(); } fn main() { unsafe { foo(); } }
Output when targeting Linux (and maybe also macOS):
error: Undefined Behavior: calling a function with ABI C using caller ABI Rust
--> src/main.rs:13:9
|
13 | foo();
| ^^^^^ calling a function with ABI C using caller ABI Rust
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavio
Output when targeting Windows:
error: Undefined Behavior: calling a function with ABI system using caller ABI C
--> <anon>:13:9
|
13 | foo();
| ^^^^^ calling a function with ABI system using caller ABI C
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
However, to my knowledge, that's not UB -- it's just unsupported by Miri (and Miri can't assume the function has "C"
or "system"
ABI since Miri doesn't know about it). I believe that is because of the overzealous check_abi()
call before the long match
in src/shims/{posix,windows}/foreign_items.rs
. The ABI is checked to match the system one ("system"
on Windows, "C"
otherwise) no matter the callee is recognized as a shim or an unsupported foreign function.
Therefore, this PR removes the check_abi()
call before the match
and inserts a check_abi()
call to each non-wildcard match.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK