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(

0 commit comments

Comments
 (0)