Open spernsteiner opened 1 year ago
I know it's not the core of the issue, but I'm curious; should *mut i32 -> &[i32]
be a supported cast?
should
*mut i32 -> &[i32]
be a supported cast?
It's difficult to support because the slice needs a length and it's not clear how we should get that number.
Do you mean when the slice is constructed?
Do you mean when the slice is constructed?
Yes, exactly. We'd have to track the slice length from the allocation origin (either an array or malloc
) in order to do this properly. We should do that, eventually, but our static analysis as is isn't really set up to do that at all at the moment, and dynamic analysis can't make guarantees about the length either.
Test case:
Analysis fails on
f
but succeeds ong
, turningg
's argument intox: &[i32]
. The rewriter tries to generate a functiong_shim
that converts from*mut i32
to&[i32]
and to modifyf
to callg_shim
in place ofg
. The modification off
succeeds, but generation ofg_shim
fails because*mut i32
->&[i32]
is not a supported cast. The result is code like this, wheref
callsg_shim
butg_shim
is never defined:One way to handle this would be to iterate rewriting to a fixpoint if any rewriting steps fail, so that neither
f
norg
gets rewritten, but no shim calls are generated.