Skip to content

Commit 7b9a20a

Browse files
svorenovaThomas Kiley
svorenova
authored and
Thomas Kiley
committed
Allow pointers to be dereferenced to void types
1 parent 108129c commit 7b9a20a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/pointer-analysis/value_set_dereference.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,26 @@ bool value_set_dereferencet::dereference_type_compare(
201201
const typet &object_type,
202202
const typet &dereference_type) const
203203
{
204-
if(dereference_type.id()==ID_empty)
205-
return true; // always ok
204+
// check if the two types have matching number of ID_pointer levels, with
205+
// the dereference type eventually pointing to void; then this is ok
206+
// for example:
207+
// - dereference_type=void is ok (no matter what object_type is);
208+
// - object_type=(int *), dereference_type=(void *) is ok;
209+
// - object_type=(int **), dereference_type=(void **) is ok;
210+
// - object_type=(int **), dereference_type=(void *) is ok;
211+
// - object_type=(int *), dereference_type=(void **) is not ok;
212+
const typet *object_unwrapped = &object_type;
213+
const typet *dereference_unwrapped = &dereference_type;
214+
while(object_unwrapped->id() == ID_pointer &&
215+
dereference_unwrapped->id() == ID_pointer)
216+
{
217+
object_unwrapped = &object_unwrapped->subtype();
218+
dereference_unwrapped = &dereference_unwrapped->subtype();
219+
}
220+
if(dereference_unwrapped->id() == ID_empty)
221+
{
222+
return true;
223+
}
206224

207225
if(base_type_eq(object_type, dereference_type, ns))
208226
return true; // ok, they just match

0 commit comments

Comments
 (0)