Skip to content

Commit 274e2ea

Browse files
committed
Avoid breaking all sharing on remove_vector/complex when the program doesn't use those features.
1 parent 09d1bfa commit 274e2ea

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

src/goto-programs/remove_complex.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,20 @@ Purpose: removes complex data type
6060
6161
\*******************************************************************/
6262

63+
static bool contains_complex(const exprt& e)
64+
{
65+
if(e.type().id()==ID_complex)
66+
return true;
67+
forall_operands(it,e)
68+
if(contains_complex(*it))
69+
return true;
70+
return false;
71+
}
72+
6373
void remove_complex(exprt &expr)
6474
{
75+
if(!contains_complex(expr))
76+
return;
6577
if(expr.id()==ID_typecast)
6678
{
6779
assert(expr.operands().size()==1);
@@ -200,8 +212,38 @@ Purpose: removes complex data type
200212
201213
\*******************************************************************/
202214

215+
static bool contains_complex(const typet& type)
216+
{
217+
if(type.id()==ID_struct || type.id()==ID_union)
218+
{
219+
const struct_union_typet &struct_union_type=
220+
to_struct_union_type(type);
221+
for(struct_union_typet::componentst::const_iterator
222+
it=struct_union_type.components().begin();
223+
it!=struct_union_type.components().end();
224+
it++)
225+
{
226+
if(contains_complex(it->type()))
227+
return true;
228+
}
229+
}
230+
else if(type.id()==ID_pointer ||
231+
type.id()==ID_vector ||
232+
type.id()==ID_array)
233+
{
234+
if(contains_complex(type.subtype()))
235+
return true;
236+
}
237+
else if(type.id()==ID_complex)
238+
return true;
239+
240+
return false;
241+
}
242+
203243
void remove_complex(typet &type)
204244
{
245+
if(!contains_complex(type))
246+
return;
205247
if(type.id()==ID_struct || type.id()==ID_union)
206248
{
207249
struct_union_typet &struct_union_type=

src/goto-programs/remove_vector.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,46 @@ Date: September 2014
1515
void remove_vector(typet &);
1616
void remove_vector(exprt &);
1717

18+
static bool contains_vector(const typet& type)
19+
{
20+
// Determine whether remove_vector is necessary, without breaking sharing.
21+
if(type.id()==ID_struct || type.id()==ID_union)
22+
{
23+
const struct_union_typet &struct_union_type=
24+
to_struct_union_type(type);
25+
26+
for(struct_union_typet::componentst::const_iterator
27+
it=struct_union_type.components().begin();
28+
it!=struct_union_type.components().end();
29+
it++)
30+
{
31+
if(contains_vector(it->type()))
32+
return true;
33+
}
34+
}
35+
else if(type.id()==ID_pointer ||
36+
type.id()==ID_complex ||
37+
type.id()==ID_array)
38+
{
39+
if(contains_vector(type.subtype()))
40+
return true;
41+
42+
}
43+
else if(type.id()==ID_vector)
44+
return true;
45+
return false;
46+
}
47+
48+
static bool contains_vector(const exprt& e)
49+
{
50+
if(e.type().id()==ID_vector)
51+
return true;
52+
forall_operands(it,e)
53+
if(contains_vector(*it))
54+
return true;
55+
return false;
56+
}
57+
1858
/*******************************************************************\
1959
2060
Function: remove_vector
@@ -29,6 +69,9 @@ Purpose: removes vector data type
2969

3070
void remove_vector(exprt &expr)
3171
{
72+
if(!contains_vector(expr))
73+
return;
74+
3275
Forall_operands(it, expr)
3376
remove_vector(*it);
3477

@@ -111,6 +154,8 @@ Purpose: removes vector data type
111154

112155
void remove_vector(typet &type)
113156
{
157+
if(!contains_vector(type))
158+
return;
114159
if(type.id()==ID_struct || type.id()==ID_union)
115160
{
116161
struct_union_typet &struct_union_type=

0 commit comments

Comments
 (0)