Skip to content

Commit 8daa27e

Browse files
authored
Merge pull request #3737 from tautschnig/remove-follow-in-util
Remove unnecessary uses of ns.follow in util/
2 parents 02744e6 + d48e62b commit 8daa27e

11 files changed

+70
-96
lines changed

src/analyses/goto_check.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ goto_checkt::address_check(const exprt &address, const exprt &size)
11731173
if(flags.is_unknown() || flags.is_dynamic_heap())
11741174
{
11751175
const or_exprt dynamic_bounds_violation(
1176-
dynamic_object_lower_bound(address, ns, nil_exprt()),
1176+
dynamic_object_lower_bound(address, nil_exprt()),
11771177
dynamic_object_upper_bound(address, ns, size));
11781178

11791179
conditions.push_back(conditiont(
@@ -1189,8 +1189,8 @@ goto_checkt::address_check(const exprt &address, const exprt &size)
11891189
flags.is_static_lifetime())
11901190
{
11911191
const or_exprt object_bounds_violation(
1192-
object_lower_bound(address, ns, nil_exprt()),
1193-
object_upper_bound(address, ns, size));
1192+
object_lower_bound(address, nil_exprt()),
1193+
object_upper_bound(address, size));
11941194

11951195
conditions.push_back(conditiont(
11961196
or_exprt(

src/util/allocate_objects.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#include "fresh_symbol.h"
1414
#include "pointer_offset_size.h"
1515
#include "string_constant.h"
16+
#include "type_eq.h"
1617

1718
/// Allocates a new object, either by creating a local variable with automatic
1819
/// lifetime, a global variable with static lifetime, or by dynamically
@@ -183,7 +184,7 @@ exprt allocate_objectst::allocate_dynamic_object(
183184
output_code.add(assign);
184185

185186
exprt malloc_symbol_expr =
186-
ns.follow(malloc_sym.symbol_expr().type()) != ns.follow(target_expr.type())
187+
!type_eq(malloc_sym.symbol_expr().type(), target_expr.type(), ns)
187188
? (exprt)typecast_exprt(malloc_sym.symbol_expr(), target_expr.type())
188189
: malloc_sym.symbol_expr();
189190

src/util/expr_initializer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
263263
{
264264
exprt result = expr_initializer_rec(ns.follow(type), source_location);
265265
// we might have mangled the type for arrays, so keep that
266-
if(ns.follow(type).id()!=ID_array)
266+
if(type.id() != ID_array)
267267
result.type()=type;
268268

269269
return result;

src/util/expr_util.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,9 @@ exprt is_not_zero(
104104
// Note that this returns a proper bool_typet(), not a C/C++ boolean.
105105
// To get a C/C++ boolean, add a further typecast.
106106

107-
const typet &src_type=
108-
src.type().id()==ID_c_enum_tag?
109-
ns.follow_tag(to_c_enum_tag_type(src.type())):
110-
ns.follow(src.type());
107+
const typet &src_type = src.type().id() == ID_c_enum_tag
108+
? ns.follow_tag(to_c_enum_tag_type(src.type()))
109+
: src.type();
111110

112111
if(src_type.id()==ID_bool) // already there
113112
return src; // do nothing

src/util/pointer_predicates.cpp

+21-36
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,15 @@ exprt good_pointer_def(
8484
const exprt &pointer,
8585
const namespacet &ns)
8686
{
87-
const pointer_typet &pointer_type=to_pointer_type(ns.follow(pointer.type()));
87+
const pointer_typet &pointer_type = to_pointer_type(pointer.type());
8888
const typet &dereference_type=pointer_type.subtype();
8989

9090
const or_exprt good_dynamic_tmp1(
9191
not_exprt(malloc_object(pointer, ns)),
9292
and_exprt(
93-
not_exprt(dynamic_object_lower_bound(pointer, ns, nil_exprt())),
94-
not_exprt(
95-
dynamic_object_upper_bound(
96-
pointer, ns, size_of_expr(dereference_type, ns)))));
93+
not_exprt(dynamic_object_lower_bound(pointer, nil_exprt())),
94+
not_exprt(dynamic_object_upper_bound(
95+
pointer, ns, size_of_expr(dereference_type, ns)))));
9796

9897
const and_exprt good_dynamic_tmp2(
9998
not_exprt(deallocated(pointer, ns)), good_dynamic_tmp1);
@@ -106,9 +105,8 @@ exprt good_pointer_def(
106105
const not_exprt not_invalid(invalid_pointer(pointer));
107106

108107
const or_exprt bad_other(
109-
object_lower_bound(pointer, ns, nil_exprt()),
110-
object_upper_bound(
111-
pointer, ns, size_of_expr(dereference_type, ns)));
108+
object_lower_bound(pointer, nil_exprt()),
109+
object_upper_bound(pointer, size_of_expr(dereference_type, ns)));
112110

113111
const or_exprt good_other(dynamic_object(pointer), not_exprt(bad_other));
114112

@@ -145,10 +143,9 @@ exprt invalid_pointer(const exprt &pointer)
145143

146144
exprt dynamic_object_lower_bound(
147145
const exprt &pointer,
148-
const namespacet &ns,
149146
const exprt &offset)
150147
{
151-
return object_lower_bound(pointer, ns, offset);
148+
return object_lower_bound(pointer, offset);
152149
}
153150

154151
exprt dynamic_object_upper_bound(
@@ -171,22 +168,17 @@ exprt dynamic_object_upper_bound(
171168
{
172169
op=ID_gt;
173170

174-
if(ns.follow(object_offset.type())!=
175-
ns.follow(access_size.type()))
176-
object_offset.make_typecast(access_size.type());
177-
sum=plus_exprt(object_offset, access_size);
171+
sum = plus_exprt(
172+
typecast_exprt::conditional_cast(object_offset, access_size.type()),
173+
access_size);
178174
}
179175

180-
if(ns.follow(sum.type())!=
181-
ns.follow(malloc_size.type()))
182-
sum.make_typecast(malloc_size.type());
183-
184-
return binary_relation_exprt(sum, op, malloc_size);
176+
return binary_relation_exprt(
177+
typecast_exprt::conditional_cast(sum, malloc_size.type()), op, malloc_size);
185178
}
186179

187180
exprt object_upper_bound(
188181
const exprt &pointer,
189-
const namespacet &ns,
190182
const exprt &access_size)
191183
{
192184
// this is
@@ -204,23 +196,19 @@ exprt object_upper_bound(
204196
{
205197
op=ID_gt;
206198

207-
if(ns.follow(object_offset.type())!=
208-
ns.follow(access_size.type()))
209-
object_offset.make_typecast(access_size.type());
210-
sum=plus_exprt(object_offset, access_size);
199+
sum = plus_exprt(
200+
typecast_exprt::conditional_cast(object_offset, access_size.type()),
201+
access_size);
211202
}
212203

213-
214-
if(ns.follow(sum.type())!=
215-
ns.follow(object_size_expr.type()))
216-
sum.make_typecast(object_size_expr.type());
217-
218-
return binary_relation_exprt(sum, op, object_size_expr);
204+
return binary_relation_exprt(
205+
typecast_exprt::conditional_cast(sum, object_size_expr.type()),
206+
op,
207+
object_size_expr);
219208
}
220209

221210
exprt object_lower_bound(
222211
const exprt &pointer,
223-
const namespacet &ns,
224212
const exprt &offset)
225213
{
226214
exprt p_offset=pointer_offset(pointer);
@@ -230,11 +218,8 @@ exprt object_lower_bound(
230218

231219
if(offset.is_not_nil())
232220
{
233-
if(ns.follow(p_offset.type())!=ns.follow(offset.type()))
234-
p_offset=
235-
plus_exprt(p_offset, typecast_exprt(offset, p_offset.type()));
236-
else
237-
p_offset=plus_exprt(p_offset, offset);
221+
p_offset = plus_exprt(
222+
p_offset, typecast_exprt::conditional_cast(offset, p_offset.type()));
238223
}
239224

240225
return binary_relation_exprt(p_offset, ID_lt, zero);

src/util/pointer_predicates.h

-3
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,16 @@ exprt integer_address(const exprt &pointer);
3333
exprt invalid_pointer(const exprt &pointer);
3434
exprt dynamic_object_lower_bound(
3535
const exprt &pointer,
36-
const namespacet &,
3736
const exprt &offset);
3837
exprt dynamic_object_upper_bound(
3938
const exprt &pointer,
4039
const namespacet &,
4140
const exprt &access_size);
4241
exprt object_lower_bound(
4342
const exprt &pointer,
44-
const namespacet &,
4543
const exprt &offset);
4644
exprt object_upper_bound(
4745
const exprt &pointer,
48-
const namespacet &,
4946
const exprt &access_size);
5047

5148
#endif // CPROVER_UTIL_POINTER_PREDICATES_H

src/util/simplify_expr.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bool simplify_exprt::simplify_abs(exprt &expr)
6767

6868
if(expr.op0().is_constant())
6969
{
70-
const typet &type=ns.follow(expr.op0().type());
70+
const typet &type = expr.op0().type();
7171

7272
if(type.id()==ID_floatbv)
7373
{
@@ -107,7 +107,7 @@ bool simplify_exprt::simplify_sign(exprt &expr)
107107

108108
if(expr.op0().is_constant())
109109
{
110-
const typet &type=ns.follow(expr.op0().type());
110+
const typet &type = expr.op0().type();
111111

112112
if(type.id()==ID_floatbv)
113113
{
@@ -163,8 +163,8 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
163163
if(expr.operands().size()!=1)
164164
return true;
165165

166-
const typet &expr_type=ns.follow(expr.type());
167-
const typet &op_type=ns.follow(expr.op0().type());
166+
const typet &expr_type = expr.type();
167+
const typet &op_type = expr.op0().type();
168168

169169
// eliminate casts of infinity
170170
if(expr.op0().id()==ID_infinity)
@@ -778,11 +778,12 @@ bool simplify_exprt::simplify_dereference(exprt &expr)
778778
if(address_of.object().id()==ID_index)
779779
{
780780
const index_exprt &old=to_index_expr(address_of.object());
781-
if(ns.follow(old.array().type()).id()==ID_array)
781+
if(old.array().type().id() == ID_array)
782782
{
783-
index_exprt idx(old.array(),
784-
plus_exprt(old.index(), pointer.op1()),
785-
ns.follow(old.array().type()).subtype());
783+
index_exprt idx(
784+
old.array(),
785+
plus_exprt(old.index(), pointer.op1()),
786+
old.array().type().subtype());
786787
simplify_rec(idx);
787788
expr.swap(idx);
788789
return false;
@@ -1347,7 +1348,7 @@ bool simplify_exprt::simplify_object(exprt &expr)
13471348
{
13481349
// kill integers from sum
13491350
Forall_operands(it, expr)
1350-
if(ns.follow(it->type()).id()==ID_pointer)
1351+
if(it->type().id() == ID_pointer)
13511352
{
13521353
exprt tmp=*it;
13531354
expr.swap(tmp);
@@ -1359,7 +1360,7 @@ bool simplify_exprt::simplify_object(exprt &expr)
13591360
else if(expr.id()==ID_typecast)
13601361
{
13611362
auto const &typecast_expr = to_typecast_expr(expr);
1362-
const typet &op_type = ns.follow(typecast_expr.op().type());
1363+
const typet &op_type = typecast_expr.op().type();
13631364

13641365
if(op_type.id()==ID_pointer)
13651366
{
@@ -1563,7 +1564,7 @@ optionalt<std::string> simplify_exprt::expr2bits(
15631564
bool little_endian)
15641565
{
15651566
// extract bits from lowest to highest memory address
1566-
const typet &type=ns.follow(expr.type());
1567+
const typet &type = expr.type();
15671568

15681569
if(expr.id()==ID_constant)
15691570
{

src/util/simplify_expr_floatbv.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bool simplify_exprt::simplify_isinf(exprt &expr)
2121
if(expr.operands().size()!=1)
2222
return true;
2323

24-
if(ns.follow(expr.op0().type()).id()!=ID_floatbv)
24+
if(expr.op0().type().id() != ID_floatbv)
2525
return true;
2626

2727
if(expr.op0().is_constant())
@@ -72,7 +72,7 @@ bool simplify_exprt::simplify_abs(exprt &expr)
7272

7373
if(expr.op0().is_constant())
7474
{
75-
const typet &type=ns.follow(expr.op0().type());
75+
const typet &type = expr.op0().type();
7676

7777
if(type.id()==ID_floatbv)
7878
{
@@ -114,7 +114,7 @@ bool simplify_exprt::simplify_sign(exprt &expr)
114114

115115
if(expr.op0().is_constant())
116116
{
117-
const typet &type=ns.follow(expr.op0().type());
117+
const typet &type = expr.op0().type();
118118

119119
if(type.id()==ID_floatbv)
120120
{
@@ -144,8 +144,8 @@ bool simplify_exprt::simplify_floatbv_typecast(exprt &expr)
144144

145145
auto const &floatbv_typecast_expr = to_floatbv_typecast_expr(expr);
146146

147-
const typet &dest_type = ns.follow(floatbv_typecast_expr.type());
148-
const typet &src_type = ns.follow(floatbv_typecast_expr.op().type());
147+
const typet &dest_type = floatbv_typecast_expr.type();
148+
const typet &src_type = floatbv_typecast_expr.op().type();
149149

150150
// eliminate redundant casts
151151
if(dest_type==src_type)
@@ -171,8 +171,8 @@ bool simplify_exprt::simplify_floatbv_typecast(exprt &expr)
171171
casted_expr.op1().id()==ID_typecast &&
172172
casted_expr.op0().operands().size()==1 &&
173173
casted_expr.op1().operands().size()==1 &&
174-
ns.follow(casted_expr.op0().type())==dest_type &&
175-
ns.follow(casted_expr.op1().type())==dest_type)
174+
casted_expr.op0().type()==dest_type &&
175+
casted_expr.op1().type()==dest_type)
176176
{
177177
exprt result(casted_expr.id(), floatbv_typecast_expr.type());
178178
result.operands().resize(3);
@@ -282,7 +282,7 @@ bool simplify_exprt::simplify_floatbv_typecast(exprt &expr)
282282

283283
bool simplify_exprt::simplify_floatbv_op(exprt &expr)
284284
{
285-
const typet &type=ns.follow(expr.type());
285+
const typet &type = expr.type();
286286

287287
PRECONDITION(type.id() == ID_floatbv);
288288
PRECONDITION(
@@ -298,10 +298,10 @@ bool simplify_exprt::simplify_floatbv_op(exprt &expr)
298298
exprt op2=expr.op2(); // rounding mode
299299

300300
INVARIANT(
301-
ns.follow(op0.type()) == type,
301+
op0.type() == type,
302302
"expression type of operand must match type of expression");
303303
INVARIANT(
304-
ns.follow(op1.type()) == type,
304+
op1.type() == type,
305305
"expression type of operand must match type of expression");
306306

307307
// Remember that floating-point addition is _NOT_ associative.

0 commit comments

Comments
 (0)