immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.79k stars 219 forks source link

(`c2rust-analyze`) Support genericity over `KnownFn` ptr perms #1006

Open kkysen opened 11 months ago

kkysen commented 11 months ago

For KnownFns like

fn strchr(
    // `WRITE` because the return type is derived from `cs`'s provenance.
    cs: *const c_char: [READ | WRITE | OFFSET_ADD | NON_NULL],
    c: c_int,
) -> *mut c_char: [READ | WRITE | OFFSET_ADD];

it would be nice for them to pass through certain permissions like we do for ptr::offset (a builtin for us). If the returned pointer is never written, there's no need to require WRITE on the argument. In other words, we'd like to be able to be generic over certain permissions, like how fn foo and fn foo_mut functions are meant to be.

Supporting this is still a ways away and not very high-priority, but I imagine we could try to implement this either by allowing permissions to be generic or to allow multiple declarations of the same fn with different permissions (like how fn foo and fn foo_mut do it) and then selecting the KnownFn with the matching permissions.