Development: wrapping pointer comparisons in casts?

Jun 4, 2010 at 8:17 AM

Hi all,

This is mostly a question to VCC developers, but any users that have insight/experience on this can definitely help.
I am currently implementing the information-flow analysis for pointer comparisons, and I noticed that VCC wraps the pointers into casts to a generic ^^u1 pointer type. This currently messes with the analysis for some yet unidentified reason (although I believe it is because the information I am interested in is carried by the typed pointer ($ptr), which is not the same after the pointer cast), so I removed the wrapper for testing purposes. My analysis now works, and it appears none of the tests were broken by removing this.
So the question is: does this pointer cast have a reason to be? (I haven't tried comparing two pointers of different types without the cast, but would that even be allowed in VCC?)


Jun 4, 2010 at 6:33 PM

Are you referring to pointer comparison? Consider the following:

struct A {

int f;

} *a;

if (a == &a->f) { ... }

This comparison in VCC is translated as “(char*)a == (char*)&a->f”. If you remove the casts then VCC will compare pointers including type information and the comparison will return false.


Jun 6, 2010 at 6:08 PM
Sorry for not seeing that one. I guess I would have expected to have them wrapped in $ref() instead of a type cast. I assume most properties (except the memory contents and the type info) are preserved by a cast to an unsigned byte? Again, thanks for all the help understanding VCC's insides. Cheers, Francois