Skip to content

Commit f14572b

Browse files
committed
Value set dereferencing: do not treat struct prefixes as equal
Two distinct struct types cannot be cast between, even when one is a prefix of the other. Value set dereferencing taking this approach just resulted in propositional encoding producing a warning about invalid type casts.
1 parent e317683 commit f14572b

File tree

6 files changed

+35
-55
lines changed

6 files changed

+35
-55
lines changed

jbmc/regression/jbmc/simplify-classid-of-interface/test_no_simplify_vccs.desc

Lines changed: 0 additions & 11 deletions
This file was deleted.

regression/cbmc/struct2/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
struct T
2+
{
3+
// intentionally empty to trigger is_prefix_of code (empty structs, however,
4+
// are a GCC-only feature)
5+
};
6+
7+
struct S
8+
{
9+
struct T t;
10+
int other;
11+
};
12+
13+
void foo(struct S s2)
14+
{
15+
struct T *p = &s2.t;
16+
struct T t2 = *p;
17+
__CPROVER_assert(0, "");
18+
}
19+
20+
int main()
21+
{
22+
struct S s;
23+
foo(s);
24+
}

regression/cbmc/struct2/test.desc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE gcc-only broken-smt-backend
2+
main.c
3+
4+
^VERIFICATION FAILED$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--
10+
This test must not generate a warning about typecasts (between different struct
11+
types) being ignored.

src/pointer-analysis/value_set_dereference.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -359,19 +359,6 @@ bool value_set_dereferencet::dereference_type_compare(
359359
if(object_type == dereference_type)
360360
return true; // ok, they just match
361361

362-
// check for struct prefixes
363-
364-
const typet ot_base=ns.follow(object_type),
365-
dt_base=ns.follow(dereference_type);
366-
367-
if(ot_base.id()==ID_struct &&
368-
dt_base.id()==ID_struct)
369-
{
370-
if(to_struct_type(dt_base).is_prefix_of(
371-
to_struct_type(ot_base)))
372-
return true; // ok, dt is a prefix of ot
373-
}
374-
375362
// we are generous about code pointers
376363
if(dereference_type.id()==ID_code &&
377364
object_type.id()==ID_code)

src/util/std_types.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,6 @@ optionalt<struct_typet::baset> struct_typet::get_base(const irep_idt &id) const
114114
return {};
115115
}
116116

117-
/// Returns true if the struct is a prefix of \a other, i.e., if this struct
118-
/// has n components then the component types and names of this struct must
119-
/// match the first n components of \a other struct.
120-
/// \param other: Struct type to compare with.
121-
bool struct_typet::is_prefix_of(const struct_typet &other) const
122-
{
123-
const componentst &ot_components=other.components();
124-
const componentst &tt_components=components();
125-
126-
if(ot_components.size()<
127-
tt_components.size())
128-
return false;
129-
130-
componentst::const_iterator
131-
ot_it=ot_components.begin();
132-
133-
for(const auto &tt_c : tt_components)
134-
{
135-
if(ot_it->type() != tt_c.type() || ot_it->get_name() != tt_c.get_name())
136-
{
137-
return false; // they just don't match
138-
}
139-
140-
ot_it++;
141-
}
142-
143-
return true; // ok, *this is a prefix of ot
144-
}
145-
146117
/// Returns true if the type is a reference.
147118
bool is_reference(const typet &type)
148119
{

src/util/std_types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ class struct_typet:public struct_union_typet
234234
{
235235
}
236236

237-
bool is_prefix_of(const struct_typet &other) const;
238-
239237
/// A struct may be a class, where members may have access restrictions.
240238
bool is_class() const
241239
{

0 commit comments

Comments
 (0)