-
Notifications
You must be signed in to change notification settings - Fork 246
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
Support intermediate casts in calls. #1022
Conversation
b9cfa49
to
c36931f
Compare
In lighttpd there are intermediate casts where the final cast is an argument to memcpy. Prior to this, only one cast was exempted, the final one. Now, all casts are skipped/allowed as long as the final cast serves as input to a function like `memcpy` or `free` or `realloc`.
95ed4b4
to
8d57764
Compare
} | ||
Some(false) => { | ||
if is_c_void_ptr(self.acx.tcx(), to_lty.ty) { | ||
// allow casts to c_void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spernsteiner this feels off to me, but the logic to exempt ancestor casts to *libc::c_void
got complicated when considering function call boundaries. Is there anything wrong with making exceptions for casts to *libc::c_void
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems okay for now. I'm hoping most of the void* cast logic will be superseded by the new pointee type analysis I'm working on.
I'm not sure I understand what you mean here. Is this about |
@spernsteiner sort of, in particular we exempt the cast in |
I took a look at this, but I'm not sure if this approach of extending |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go ahead with this approach for now, even if some of it may be superseded by future work.
} | ||
Some(false) => { | ||
if is_c_void_ptr(self.acx.tcx(), to_lty.ty) { | ||
// allow casts to c_void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems okay for now. I'm hoping most of the void* cast logic will be superseded by the new pointee type analysis I'm working on.
c2rust-analyze/src/c_void_casts.rs
Outdated
pub fn rv_place<'tcx>(rv: &Rvalue<'tcx>) -> Option<Place<'tcx>> { | ||
use Rvalue::*; | ||
match rv { | ||
Use(op) => op.place(), | ||
Repeat(op, _) => op.place(), | ||
Ref(_, _, p) => Some(*p), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this function? It doesn't seem like a very meaningful operation, since the Place
s it returns are used in all sorts of different ways depending on what kind of Rvalue
was passed. For example, some Rvalue
s read from rv_place(rv)
, while others don't.
Looking at the use site below, it seems like this is part of the logic for propagating through multiple levels of casts, as in p as *const c_char as *const c_void
. If that's the case, can this be reduced to the Cast
case only, where the meaning is clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, now only addressing Use
and Cast
in a1fbda0
In lighttpd there are intermediate casts where the final cast is an argument to
memcpy
ormemset
. Prior to this, only one cast to*libc::c_void
was exempted, the final one. Now, all casts are skipped/allowed as long as the final cast serves as input to a function likememcpy
orfree
orrealloc
. Also, any non-skipped casts into*libc::c_void
are now allowed to support cast ancestry that crosses function call boundaries, as the intra-body analysis starting backwards frommemset
andmemcpy
does not capture these cases.The contents of
algo_md5.rs
match exactly the transpiled output fromlighttpd
with no alterations made.