Skip to content

Commit 92a84dc

Browse files
author
thk123
committed
Extracted out logic for when to use a 2 value merge
Previously each abstract object that implemented merge had to correctly redirect merging top with anything or merging with a bottom. This is now handled directly in the root merge by checking the three cases where the base merge must be used. If this is bottom must still be handled by derived classes as we must create an abstract object of the same type.
1 parent c1736c4 commit 92a84dc

File tree

6 files changed

+51
-22
lines changed

6 files changed

+51
-22
lines changed

src/analyses/variable-sensitivity/abstract_object.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ Function: abstract_objectt::merge
112112

113113
abstract_object_pointert abstract_objectt::merge(
114114
abstract_object_pointert other) const
115+
{
116+
return abstract_object_merge(other);
117+
}
118+
119+
/*******************************************************************\
120+
121+
Function: abstract_objectt::abstract_object_merge
122+
123+
Inputs:
124+
other - The object to merge with this
125+
126+
Outputs: Returns the result of the abstract object.
127+
128+
Purpose: Create a new abstract object that is the result of the merge, unless
129+
the object would be unchanged, then would return itself.
130+
131+
\*******************************************************************/
132+
133+
abstract_object_pointert abstract_objectt::abstract_object_merge(
134+
const abstract_object_pointert other) const
115135
{
116136
if(top)
117137
return shared_from_this();
@@ -125,7 +145,6 @@ abstract_object_pointert abstract_objectt::merge(
125145
return merged;
126146
}
127147

128-
129148
/*******************************************************************\
130149
131150
Function: abstract_objectt::expression_transform
@@ -286,10 +305,31 @@ abstract_object_pointert abstract_objectt::merge(
286305
abstract_object_pointert op2,
287306
bool &out_modifications)
288307
{
289-
abstract_object_pointert result=op1->merge(op2);
308+
abstract_object_pointert result=op1->should_use_base_merge(op2)?
309+
op1->abstract_object_merge(op2):op1->merge(op2);
290310
// If no modifications, we will return the original pointer
291311
out_modifications=result!=op1;
292312
return result;
293313
}
294314

315+
/*******************************************************************\
316+
317+
Function: abstract_objectt::should_use_base_merge
318+
319+
Inputs:
320+
other - the object being merged with
321+
322+
Outputs: Returns true if the base class is capable of doing a complete merge
323+
324+
Purpose: To detect the cases where the base merge is sufficient to do a merge
325+
We can't do if this->is_bottom() since we want the specific
326+
327+
\*******************************************************************/
328+
329+
bool abstract_objectt::should_use_base_merge(
330+
const abstract_object_pointert other) const
331+
{
332+
return is_top() || other->is_bottom() || other->is_top();
333+
}
334+
295335

src/analyses/variable-sensitivity/abstract_object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ class abstract_objectt:public std::enable_shared_from_this<abstract_objectt>
112112
// To enforce copy-on-write these are private and have read-only accessors
113113
typet t;
114114
bool bottom;
115+
116+
abstract_object_pointert abstract_object_merge(
117+
const abstract_object_pointert other) const;
115118
protected:
116119
template<class T>
117120
using internal_sharing_ptrt=std::shared_ptr<T>;
@@ -130,6 +133,8 @@ class abstract_objectt:public std::enable_shared_from_this<abstract_objectt>
130133
// The one exception is merge in descendant classes, which needs this
131134
void make_top() { top=true; }
132135

136+
bool should_use_base_merge(const abstract_object_pointert other) const;
137+
133138
// Sets the state of this object
134139
virtual abstract_object_pointert merge(abstract_object_pointert other) const;
135140

src/analyses/variable-sensitivity/constant_abstract_value.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ Function: constant_abstract_valuet::merge_constant_constant
101101
abstract_object_pointert constant_abstract_valuet::merge_constant_constant(
102102
constant_abstract_value_pointert other) const
103103
{
104-
if(is_top() || other->is_bottom())
105-
{
106-
return abstract_valuet::merge(other);
107-
}
108-
else if(is_bottom())
104+
if(is_bottom())
109105
{
110106
return std::make_shared<constant_abstract_valuet>(*other);
111107
}

src/analyses/variable-sensitivity/constant_array_abstract_object.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ Function: constant_array_abstract_objectt::constant_array_merge
133133
abstract_object_pointert constant_array_abstract_objectt::constant_array_merge(
134134
const constant_array_pointert other) const
135135
{
136-
if(is_top() || other->is_bottom() || other->is_top())
137-
{
138-
return array_abstract_objectt::merge(other);
139-
}
140-
else if(is_bottom())
136+
if(is_bottom())
141137
{
142138
return std::make_shared<constant_array_abstract_objectt>(*other);
143139
}

src/analyses/variable-sensitivity/constant_pointer_abstract_object.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,7 @@ abstract_object_pointert
168168
constant_pointer_abstract_objectt::merge_constant_pointers(
169169
const constant_pointer_abstract_pointert other) const
170170
{
171-
if(is_top() || other->is_bottom())
172-
{
173-
return pointer_abstract_objectt::merge(other);
174-
}
175-
else if(is_bottom())
171+
if(is_bottom())
176172
{
177173
return std::make_shared<constant_pointer_abstract_objectt>(*other);
178174
}

src/analyses/variable-sensitivity/full_struct_abstract_object.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,7 @@ Function: full_struct_abstract_objectt::merge_constant_structs
360360
abstract_object_pointert full_struct_abstract_objectt::merge_constant_structs(
361361
constant_struct_pointert other) const
362362
{
363-
if(is_top() || other->is_bottom() || other->is_top())
364-
{
365-
return struct_abstract_objectt::merge(other);
366-
}
367-
else if(is_bottom())
363+
if(is_bottom())
368364
{
369365
return std::make_shared<full_struct_abstract_objectt>(*other);
370366
}

0 commit comments

Comments
 (0)