-
Notifications
You must be signed in to change notification settings - Fork 505
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
Is UB in FFI also UB in Rust? #485
Comments
One more question: would in be an UB in C if we:
2.a. call it in C: 2.b create a wrapper of Rust's add_one inside C and call it from Rust: C code:
Rust code:
|
This is one of those things that's currently an area of active research, so nobody has any idea. |
@ubsan is this the answer to the first or the second question (or both)? |
@kpp the second question - if you have UB in C code that you call, then your program has UB. It's not Rust UB, because that doesn't make a lot of sense. |
It causes UB in your entire program. The UB originates from the C part, so it's not "UB in Rust", but that doesn't help at all -- if you link together pieces written in different languages with a conventional linker, UB in any component "bleeds" into all the other components. |
@kpp every piece of code is evaluated following the rules of the language it is written in. Integer overflow is not UB in Rust, so it is also not UB in Rust when that code is called from C. (That's what the question is about, right?) So that whole program does not have UB. |
Awesome! Thanks! What about the main question: I consider adding one more item into the list of Behavior considered undefined:
|
I don't know if that's helpful. It's not UB in Rust to have UB in C, it's just UB in your program. But FFI should probably appear in that list somewhere. |
Link to ref: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
My question is:
Does undefined behavior inside an extern FFI function also cause an UB in Rust?
There is an item inside of the list of Behavior considered undefined:
I consider adding one more item:
The text was updated successfully, but these errors were encountered: