-
Notifications
You must be signed in to change notification settings - Fork 386
Calling a C function with a wrong type from Miri results in panic #1355
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
Comments
Thanks for the report! I moved this to the Miri tracker. This is conceptually close to #1272, but much harder to fix than that. We'd need variants of our The good news is that I don't think this issue can hide UB, it just leads to bad error messages. |
Well I guess an alternative might be to adjust our existing |
So basically rustc will always be fine with the panicking variants, but miri needs non-panicking variants? I guess we could play with extension traits to get such behaviour differences between miri and ctfe/engine but that would be very confusing. I'm fine with just making all the methods return results, even if most/all of the errors reported on these mean bugs in ctfe/engine, but it may make debugging harder if we actually have bugs again there. Similar to the |
It may actually also make debugging easier because errors, unlike assertions, point to the MIR span that was evaluated when they got triggered. ;) |
I'd like to work on this issue. |
@samrat great. :) This issue will mostly (maybe entirely) require work on rustc, where the assertions that we are hitting lie. The first step (and maybe the only step) is to turn this assertion into raising an appropriate interpreter error instead: Probably a new variant should be added to this enum for that purpose: Once that fix lands on rustc, a testcase should be added to Miri. |
…RalfJung [miri] Throw UB if target size and data size don't match Issue: rust-lang/miri#1355 If an extern C function is defined as ``` extern "C" { fn malloc(size: u32) -> *mut std::ffi::c_void; } ``` on a 64-bit machine(ie. pointer sizes don't match), return undefined behaviour from Miri when [converting the argument into machine_usize](https://github.com/rust-lang/miri/blob/master/src/shims/foreign_items.rs#L200)
Code
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c161d6b819c07b126414739cf6e32274
Meta
rustc 1.44.0-nightly (3712e11a8 2020-04-12) running on x86_64-unknown-linux-gnu
Error output
The text was updated successfully, but these errors were encountered: