-
Notifications
You must be signed in to change notification settings - Fork 259
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
Incorrect translation of alloca
in block scope
#759
Comments
Also, |
Ideally, yes, but that may not be possible as Rust does not have |
alloca
in block scope
That only handles a subset of the possible uses of |
Besides, after [ERROR @ c2rust-analyze/src/dataflow/type_check.rs:501 @ c2rust_analyze::dataflow::type_check]: TODO: visit Callee::UnknownDef(Direct { ty: fn(i32, usize) -> std::vec::Vec<i32> {std::vec::from_elem::<i32>}, def_id: DefId(5:7923 ~ alloc[3757]::vec::from_elem), substs: [i32], is_foreign: false }) it seems that |
Tested with c2rust 0.16.0
This is a program that has no memory errors. The
if (one)
is guaranteed to be entered, though the compiler cannot see that, and the result of__builtin_alloca
persists until the function ends, even after the block has ended.It is translated to the following Rust code:
Note here the
let mut fresh0 = ::std::vec::from_elem(0, 100 as libc::c_int as libc::c_uint as usize);
in block scope. Here, unlike in the C program, the vec will be dropped when the block is exited, andp
is left a dangling pointer.A possible corrected translation would be to make
fresh0
a function-scope variable.The text was updated successfully, but these errors were encountered: