-
Notifications
You must be signed in to change notification settings - Fork 84
Limiting casts: No cast on read from a variable #146
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
Conversation
|
Still happens for:
|
|
One of the failing ones is due to this pattern: #include<stdio.h>
struct __anonstruct_mbox_t_232 {
int one;
int two;
};
typedef struct __anonstruct_mbox_t_232 mbox_t;
int main(void) {
unsigned char raw_mbox[15U];
mbox_t *mbox ;
mbox = (mbox_t *)(& raw_mbox);
memset((void *)(& mbox->one), 0, 15UL);
} |
|
One case we looked at in #119 did something similar: #119 (comment). Using an array of a primitive type always cast to some struct. |
|
I am very tempted to do this on a best-effort base: let is_heap_var = match a (Q.IsHeapVar x) with `Bool(true) -> true | _ -> false in
if is_heap_var then
(* the vtype of heap vars will be TVoid, so we need to trust the pointer we *)
(* got to this to be of the right type *)
(* i.e. use the static type of the pointer here *)
lval_type
else
try
Cil.typeOfLval (Var x, cil_offset)
with _ ->
lval_typeSo we would go with the type of the |
|
I'm wondering if it's be a good idea to make the |
Yes, good idea! Feel free to add, or I can do it tomorrow morning. |
Following up on all of these discussion with casting for writes through pointers of different types, I took a look at the standard (see Slack).
The resulting idea is casting to the pointed-to type on writes via pointers to memory that has not been dynamically allocated, and casting on reads for dynamically allocated memory.
I will have to test if this causes #119 to resurface. To this end, if we check that
Cil.typeOfLvalis only called onlvalsstemming from the C-program, we should be good. I'll also run the tests that showed #119 again.This a a prerequisite for merging #145 (and also #137 iirc). It will require changes to #121 such that values of two different
ikindscan once again be joined, yieldingtop.