Skip to content

Commit 1e3f64d

Browse files
authored
Merge pull request #4314 from tautschnig/base_type-object-types
Do not use base_type_eq with non-code types [blocks: #4056]
2 parents 98103ff + cb67b9b commit 1e3f64d

31 files changed

+88
-130
lines changed

jbmc/unit/java-testing-utils/require_type.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Author: Diffblue Ltd.
99
#include "require_type.h"
1010

1111
#include <testing-utils/use_catch.h>
12-
#include <util/base_type.h>
1312
#include <util/namespace.h>
1413
#include <util/symbol_table.h>
1514

@@ -26,10 +25,8 @@ pointer_typet require_type::require_pointer(
2625
const pointer_typet &pointer = to_pointer_type(type);
2726

2827
if(subtype)
29-
{
30-
namespacet ns{symbol_tablet{}};
31-
base_type_eq(pointer.subtype(), subtype.value(), ns);
32-
}
28+
REQUIRE(pointer.subtype() == subtype.value());
29+
3330
return pointer;
3431
}
3532

src/analyses/constant_propagator.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Author: Peter Schrammel
1717
#endif
1818

1919
#include <util/arith_tools.h>
20-
#include <util/base_type.h>
2120
#include <util/c_types.h>
2221
#include <util/cprover_prefix.h>
2322
#include <util/expr_util.h>
@@ -103,7 +102,7 @@ void constant_propagator_domaint::assign_rec(
103102
if(dest_values.is_constant(tmp))
104103
{
105104
DATA_INVARIANT(
106-
base_type_eq(ns.lookup(s).type, tmp.type(), ns),
105+
ns.lookup(s).type == tmp.type(),
107106
"type of constant to be replaced should match");
108107
dest_values.set_to(s, tmp);
109108
}
@@ -624,7 +623,7 @@ bool constant_propagator_domaint::valuest::meet(
624623
{
625624
const typet &m_id_type = ns.lookup(m.first).type;
626625
DATA_INVARIANT(
627-
base_type_eq(m_id_type, m.second.type(), ns),
626+
m_id_type == m.second.type(),
628627
"type of constant to be stored should match");
629628
set_to(symbol_exprt(m.first, m_id_type), m.second);
630629
changed=true;

src/goto-instrument/dump_c.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "dump_c.h"
1313

14-
#include <util/base_type.h>
1514
#include <util/config.h>
1615
#include <util/find_symbols.h>
1716
#include <util/invariant.h>
@@ -1277,9 +1276,9 @@ void dump_ct::cleanup_expr(exprt &expr)
12771276
expr.swap(tmp);
12781277
}
12791278
}
1280-
else if(expr.id()==ID_typecast &&
1281-
expr.op0().id()==ID_typecast &&
1282-
base_type_eq(expr.type(), expr.op0().type(), ns))
1279+
else if(
1280+
expr.id() == ID_typecast && expr.op0().id() == ID_typecast &&
1281+
expr.type() == expr.op0().type())
12831282
{
12841283
exprt tmp=expr.op0();
12851284
expr.swap(tmp);
@@ -1309,8 +1308,7 @@ void dump_ct::cleanup_expr(exprt &expr)
13091308
if(type.id()==ID_union &&
13101309
type.get_bool(ID_C_transparent_union))
13111310
{
1312-
if(it2->id()==ID_typecast &&
1313-
base_type_eq(it2->type(), type, ns))
1311+
if(it2->id() == ID_typecast && it2->type() == type)
13141312
*it2=to_typecast_expr(*it2).op();
13151313

13161314
// add a typecast for NULL or 0

src/goto-programs/goto_inline_class.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Author: Daniel Kroening, [email protected]
1515
#include <iostream>
1616
#endif
1717

18-
#include <util/base_type.h>
1918
#include <util/cprover_prefix.h>
2019
#include <util/expr_util.h>
2120
#include <util/invariant.h>
@@ -83,7 +82,7 @@ void goto_inlinet::parameter_assignments(
8382
{
8483
// it should be the same exact type as the parameter,
8584
// subject to some exceptions
86-
if(!base_type_eq(parameter_type, actual.type(), ns))
85+
if(parameter_type != actual.type())
8786
{
8887
const typet &f_partype = parameter_type;
8988
const typet &f_acttype = actual.type();

src/goto-programs/goto_program.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414
#include <ostream>
1515
#include <iomanip>
1616

17+
#include <util/base_type.h>
1718
#include <util/expr_iterator.h>
1819
#include <util/find_symbols.h>
1920
#include <util/invariant.h>
@@ -715,10 +716,9 @@ void goto_programt::instructiont::validate(
715716
// Return removal sets the return type of a function symbol table
716717
// entry to 'void', but some callsites still expect the original
717718
// type (e.g. if a function is passed as a parameter)
718-
symbol_expr_type_matches_symbol_table = base_type_eq(
719-
goto_symbol_expr.type(),
720-
original_return_type(ns.get_symbol_table(), goto_id),
721-
ns);
719+
symbol_expr_type_matches_symbol_table =
720+
goto_symbol_expr.type() ==
721+
original_return_type(ns.get_symbol_table(), goto_id);
722722

723723
if(
724724
!symbol_expr_type_matches_symbol_table &&
@@ -760,8 +760,8 @@ void goto_programt::instructiont::validate(
760760
auto symbol_table_array_type = to_array_type(table_symbol->type);
761761
symbol_table_array_type.size() = nil_exprt();
762762

763-
symbol_expr_type_matches_symbol_table = base_type_eq(
764-
goto_symbol_expr.type(), symbol_table_array_type, ns);
763+
symbol_expr_type_matches_symbol_table =
764+
goto_symbol_expr.type() == symbol_table_array_type;
765765
}
766766
}
767767

src/goto-programs/graphml_witness.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Author: Daniel Kroening
1111

1212
#include "graphml_witness.h"
1313

14-
#include <util/base_type.h>
1514
#include <util/byte_operators.h>
1615
#include <util/c_types.h>
1716
#include <util/arith_tools.h>
@@ -75,8 +74,9 @@ std::string graphml_witnesst::convert_assign_rec(
7574
{
7675
// dereferencing may have resulted in an lhs that is the first
7776
// struct member; undo this
78-
if(assign.lhs().id()==ID_member &&
79-
!base_type_eq(assign.lhs().type(), assign.rhs().type(), ns))
77+
if(
78+
assign.lhs().id() == ID_member &&
79+
assign.lhs().type() != assign.rhs().type())
8080
{
8181
code_assignt tmp=assign;
8282
tmp.lhs()=to_member_expr(assign.lhs()).struct_op();

src/goto-programs/wp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Author: Daniel Kroening, [email protected]
1515

1616
#include <util/std_expr.h>
1717
#include <util/std_code.h>
18-
#include <util/base_type.h>
1918

2019
#include <util/invariant.h>
2120

@@ -79,7 +78,7 @@ aliasingt aliasing(
7978
return aliasing(e1, e2.op0().op0(), ns);
8079

8180
// fairly radical. Ignores struct prefixes and the like.
82-
if(!base_type_eq(e1.type(), e2.type(), ns))
81+
if(e1.type() != e2.type())
8382
return aliasingt::A_MUSTNOT;
8483

8584
// syntactically the same?

src/goto-symex/symex_assign.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ void goto_symext::symex_assign(statet &state, const code_assignt &code)
2727
exprt rhs=code.rhs();
2828

2929
DATA_INVARIANT(
30-
base_type_eq(lhs.type(), rhs.type(), ns),
31-
"assignments must be type consistent");
30+
lhs.type() == rhs.type(), "assignments must be type consistent");
3231

3332
clean_expr(lhs, state, true);
3433
clean_expr(rhs, state, false);

src/goto-symex/symex_clean_expr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Author: Daniel Kroening, [email protected]
1212
#include "goto_symex.h"
1313

1414
#include <util/arith_tools.h>
15-
#include <util/base_type.h>
1615
#include <util/byte_operators.h>
1716
#include <util/c_types.h>
1817
#include <util/pointer_offset_size.h>
@@ -37,7 +36,7 @@ process_array_expr(exprt &expr, bool do_simplify, const namespacet &ns)
3736
process_array_expr(if_expr.true_case(), do_simplify, ns);
3837
process_array_expr(if_expr.false_case(), do_simplify, ns);
3938

40-
if(!base_type_eq(if_expr.true_case(), if_expr.false_case(), ns))
39+
if(if_expr.true_case() != if_expr.false_case())
4140
{
4241
byte_extract_exprt be(
4342
byte_extract_id(),

src/goto-symex/symex_dereference.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Author: Daniel Kroening, [email protected]
1212
#include "goto_symex.h"
1313

1414
#include <util/arith_tools.h>
15-
#include <util/base_type.h>
1615
#include <util/byte_operators.h>
1716
#include <util/c_types.h>
1817
#include <util/exception_utils.h>
@@ -61,7 +60,7 @@ exprt goto_symext::address_arithmetic(
6160

6261
// turn &a of type T[i][j] into &(a[0][0])
6362
for(const typet *t = &(a.type().subtype());
64-
t->id() == ID_array && !base_type_eq(expr.type(), *t, ns);
63+
t->id() == ID_array && expr.type() != *t;
6564
t = &(t->subtype()))
6665
a.object()=index_exprt(a.object(), from_integer(0, index_type()));
6766
}
@@ -184,9 +183,10 @@ exprt goto_symext::address_arithmetic(
184183
"goto_symext::address_arithmetic does not handle " + expr.id_string());
185184

186185
const typet &expr_type = expr.type();
187-
INVARIANT((expr_type.id()==ID_array && !keep_array) ||
188-
base_type_eq(pointer_type(expr_type), result.type(), ns),
189-
"either non-persistent array or pointer to result");
186+
INVARIANT(
187+
(expr_type.id() == ID_array && !keep_array) ||
188+
pointer_type(expr_type) == result.type(),
189+
"either non-persistent array or pointer to result");
190190

191191
return result;
192192
}
@@ -286,12 +286,11 @@ void goto_symext::dereference_rec(exprt &expr, statet &state)
286286
exprt &tc_op=to_typecast_expr(expr).op();
287287

288288
// turn &array into &array[0] when casting to pointer-to-element-type
289-
if(tc_op.id()==ID_address_of &&
290-
to_address_of_expr(tc_op).object().type().id()==ID_array &&
291-
base_type_eq(
292-
expr.type(),
293-
pointer_type(to_address_of_expr(tc_op).object().type().subtype()),
294-
ns))
289+
if(
290+
tc_op.id() == ID_address_of &&
291+
to_address_of_expr(tc_op).object().type().id() == ID_array &&
292+
expr.type() ==
293+
pointer_type(to_address_of_expr(tc_op).object().type().subtype()))
295294
{
296295
expr=
297296
address_of_exprt(

src/goto-symex/symex_function_call.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Author: Daniel Kroening, [email protected]
1212
#include "goto_symex.h"
1313

1414
#include <util/arith_tools.h>
15-
#include <util/base_type.h>
1615
#include <util/byte_operators.h>
1716
#include <util/c_types.h>
1817
#include <util/exception_utils.h>
@@ -80,7 +79,7 @@ void goto_symext::parameter_assignments(
8079
else
8180
{
8281
// It should be the same exact type.
83-
if(!base_type_eq(parameter_type, rhs.type(), ns))
82+
if(parameter_type != rhs.type())
8483
{
8584
const typet &rhs_type = rhs.type();
8685

src/goto-symex/symex_other.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Author: Daniel Kroening, [email protected]
1212
#include "goto_symex.h"
1313

1414
#include <util/arith_tools.h>
15-
#include <util/base_type.h>
1615
#include <util/byte_operators.h>
1716
#include <util/c_types.h>
1817
#include <util/pointer_offset_size.h>
@@ -149,7 +148,7 @@ void goto_symext::symex_other(
149148
process_array_expr(state, src_array);
150149

151150
// check for size (or type) mismatch and adjust
152-
if(!base_type_eq(dest_array.type(), src_array.type(), ns))
151+
if(dest_array.type() != src_array.type())
153152
{
154153
if(statement==ID_array_copy)
155154
{
@@ -217,7 +216,7 @@ void goto_symext::symex_other(
217216

218217
const array_typet &array_type = to_array_type(array_expr.type());
219218

220-
if(!base_type_eq(array_type.subtype(), value.type(), ns))
219+
if(array_type.subtype() != value.type())
221220
value = typecast_exprt(value, array_type.subtype());
222221

223222
code_assignt assignment(array_expr, array_of_exprt(value, array_type));
@@ -250,7 +249,7 @@ void goto_symext::symex_other(
250249
code_assignt assignment(code.op2(), equal_exprt(array1, array2));
251250

252251
// check for size (or type) mismatch
253-
if(!base_type_eq(array1.type(), array2.type(), ns))
252+
if(array1.type() != array2.type())
254253
assignment.lhs() = false_exprt();
255254

256255
symex_assign(state, assignment);

src/goto-symex/symex_target_equation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ void symex_target_equationt::SSA_stept::validate(
940940
validate_full_expr(ssa_rhs, ns, vm);
941941
DATA_CHECK(
942942
vm,
943-
base_type_eq(ssa_lhs.get_original_expr().type(), ssa_rhs.type(), ns),
943+
ssa_lhs.get_original_expr().type() == ssa_rhs.type(),
944944
"Type inequality in SSA assignment\nlhs-type: " +
945945
ssa_lhs.get_original_expr().type().id_string() +
946946
"\nrhs-type: " + ssa_rhs.type().id_string());

src/pointer-analysis/value_set.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Author: Daniel Kroening, [email protected]
1515
#include <ostream>
1616

1717
#include <util/arith_tools.h>
18-
#include <util/base_type.h>
1918
#include <util/c_types.h>
2019
#include <util/pointer_offset_size.h>
2120
#include <util/prefix.h>
@@ -1155,10 +1154,10 @@ void value_sett::assign(
11551154
}
11561155
else
11571156
{
1158-
if(!base_type_eq(rhs.type(), type, ns))
1157+
if(rhs.type() != lhs.type())
11591158
throw "value_sett::assign type mismatch: "
11601159
"rhs.type():\n"+rhs.type().pretty()+"\n"+
1161-
"type:\n"+type.pretty();
1160+
"lhs.type():\n"+lhs.type().pretty();
11621161

11631162
rhs_member=make_member(rhs, name, ns);
11641163

@@ -1183,7 +1182,7 @@ void value_sett::assign(
11831182
}
11841183
else
11851184
{
1186-
if(!base_type_eq(rhs.type(), type, ns))
1185+
if(rhs.type() != type)
11871186
throw "value_sett::assign type mismatch: "
11881187
"rhs.type():\n"+rhs.type().pretty()+"\n"+
11891188
"type:\n"+type.pretty();

src/pointer-analysis/value_set_dereference.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Author: Daniel Kroening, [email protected]
1818

1919
#include <util/arith_tools.h>
2020
#include <util/array_name.h>
21-
#include <util/base_type.h>
2221
#include <util/byte_operators.h>
2322
#include <util/c_types.h>
2423
#include <util/config.h>
@@ -208,7 +207,7 @@ bool value_set_dereferencet::dereference_type_compare(
208207
#endif
209208
}
210209

211-
if(base_type_eq(object_type, dereference_type, ns))
210+
if(object_type == dereference_type)
212211
return true; // ok, they just match
213212

214213
// check for struct prefixes
@@ -314,7 +313,7 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to(
314313
const symbolt &memory_symbol=ns.lookup(CPROVER_PREFIX "memory");
315314
const symbol_exprt symbol_expr(memory_symbol.name, memory_symbol.type);
316315

317-
if(base_type_eq(memory_symbol.type.subtype(), dereference_type, ns))
316+
if(memory_symbol.type.subtype() == dereference_type)
318317
{
319318
// Types match already, what a coincidence!
320319
// We can use an index expression.

src/pointer-analysis/value_set_fi.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Author: Daniel Kroening, [email protected]
1616

1717
#include <util/symbol_table.h>
1818
#include <util/simplify_expr.h>
19-
#include <util/base_type.h>
2019
#include <util/std_expr.h>
2120
#include <util/prefix.h>
2221
#include <util/std_code.h>
@@ -990,10 +989,10 @@ void value_set_fit::assign(
990989
}
991990
else
992991
{
993-
if(!base_type_eq(rhs.type(), type, ns))
992+
if(rhs.type() != lhs.type())
994993
throw "value_set_fit::assign type mismatch: "
995994
"rhs.type():\n"+rhs.type().pretty()+"\n"+
996-
"type:\n"+type.pretty();
995+
"type:\n"+lhs.type().pretty();
997996

998997
if(rhs.id()==ID_struct ||
999998
rhs.id()==ID_constant)
@@ -1051,7 +1050,7 @@ void value_set_fit::assign(
10511050
}
10521051
else
10531052
{
1054-
if(!base_type_eq(rhs.type(), type, ns))
1053+
if(rhs.type() != type)
10551054
throw "value_set_fit::assign type mismatch: "
10561055
"rhs.type():\n"+rhs.type().pretty()+"\n"+
10571056
"type:\n"+type.pretty();

0 commit comments

Comments
 (0)