Skip to content

Commit 4a5da20

Browse files
authored
Merge pull request #6951 from diffblue/equal_exprt_type_check
equal_exprt now checks types of the operands
2 parents adf0a44 + 4ab7663 commit 4a5da20

File tree

11 files changed

+47
-33
lines changed

11 files changed

+47
-33
lines changed

src/analyses/variable-sensitivity/full_struct_abstract_object.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,13 @@ abstract_object_pointert full_struct_abstract_objectt::visit_sub_elements(
305305
exprt full_struct_abstract_objectt::to_predicate_internal(
306306
const exprt &name) const
307307
{
308+
const auto &compound_type = to_struct_union_type(name.type());
308309
auto all_predicates = exprt::operandst{};
309310

310311
for(auto field : map.get_sorted_view())
311312
{
312-
auto field_name = member_exprt(name, field.first, name.type());
313+
auto field_name =
314+
member_exprt(name, compound_type.get_component(field.first));
313315
auto field_expr = field.second->to_predicate(field_name);
314316

315317
if(!field_expr.is_true())

src/cpp/cpp_typecheck_code.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ void cpp_typecheckt::typecheck_code(codet &code)
7373
shl_exprt shl{from_integer(1, array.type()),
7474
to_index_expr(binary_expr.op0()).index()};
7575
exprt rhs = if_exprt{
76-
equal_exprt{binary_expr.op1(), from_integer(0, array.type())},
76+
equal_exprt{
77+
binary_expr.op1(), from_integer(0, binary_expr.op1().type())},
7778
bitand_exprt{array, bitnot_exprt{shl}},
7879
bitor_exprt{array, shl}};
7980
binary_expr.op0() = to_index_expr(binary_expr.op0()).array();

src/goto-symex/symex_other.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,13 @@ void goto_symext::symex_other(
224224
process_array_expr(state, array1);
225225
process_array_expr(state, array2);
226226

227-
exprt rhs = equal_exprt(array1, array2);
227+
exprt rhs;
228228

229-
// check for size (or type) mismatch
229+
// Types don't match? Make it 'false'.
230230
if(array1.type() != array2.type())
231231
rhs = false_exprt();
232+
else
233+
rhs = equal_exprt(array1, array2);
232234

233235
symex_assign(state, code.op2(), rhs);
234236
}

src/linking/linking.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,17 @@ bool linkingt::adjust_object_type_rec(
949949
}
950950
else
951951
{
952+
if(new_size.type() != old_size.type())
953+
{
954+
link_error(
955+
info.old_symbol,
956+
info.new_symbol,
957+
"conflicting array sizes for variable");
958+
959+
// error logged, continue typechecking other symbols
960+
return true;
961+
}
962+
952963
equal_exprt eq(old_size, new_size);
953964

954965
if(!simplify_expr(eq, ns).is_true())

src/statement-list/parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,8 +1098,8 @@ Param_Assignment:
10981098
Variable_Name TOK_ASSIGNMENT IL_Operand
10991099
{
11001100
newstack($$);
1101-
parser_stack($$) = equal_exprt{std::move(parser_stack($1)),
1102-
std::move(parser_stack($3))};
1101+
parser_stack($$) = code_frontend_assignt(std::move(parser_stack($1)),
1102+
std::move(parser_stack($3)));
11031103
}
11041104
;
11051105
Opt_Data_Block:

src/statement-list/statement_list_parse_tree_io.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ static void output_constant(std::ostream &os, const constant_exprt &constant)
4040
/// Prints the assignment of a module parameter to the given output stream.
4141
/// \param [out] os: Stream that should receive the result.
4242
/// \param assignment: Assignment that shall be printed.
43-
static void
44-
output_parameter_assignment(std::ostream &os, const equal_exprt &assignment)
43+
static void output_parameter_assignment(
44+
std::ostream &os,
45+
const code_frontend_assignt &assignment)
4546
{
4647
os << assignment.lhs().get(ID_identifier) << " := ";
4748
const constant_exprt *const constant =
@@ -246,11 +247,10 @@ void output_instruction(
246247
output_constant(os, *constant);
247248
continue;
248249
}
249-
const equal_exprt *const equal = expr_try_dynamic_cast<equal_exprt>(expr);
250-
if(equal)
250+
if(const auto assign = expr_try_dynamic_cast<code_frontend_assignt>(expr))
251251
{
252252
os << "\n\t";
253-
output_parameter_assignment(os, *equal);
253+
output_parameter_assignment(os, *assign);
254254
continue;
255255
}
256256
os << '\t' << expr.id();

src/statement-list/statement_list_typecheck.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,9 +1593,9 @@ void statement_list_typecheckt::typecheck_CPROVER_assert(
15931593
const codet &op_code,
15941594
symbolt &tia_element)
15951595
{
1596-
const equal_exprt *const assignment =
1597-
expr_try_dynamic_cast<equal_exprt>(op_code.op1());
1598-
if(assignment)
1596+
if(
1597+
const auto assignment =
1598+
expr_try_dynamic_cast<code_frontend_assignt>(op_code.op1()))
15991599
{
16001600
const code_assertt assertion{
16011601
typecheck_function_call_argument_rhs(tia_element, assignment->rhs())};
@@ -1612,9 +1612,9 @@ void statement_list_typecheckt::typecheck_CPROVER_assume(
16121612
const codet &op_code,
16131613
symbolt &tia_element)
16141614
{
1615-
const equal_exprt *const assignment =
1616-
expr_try_dynamic_cast<equal_exprt>(op_code.op1());
1617-
if(assignment)
1615+
if(
1616+
const auto assignment =
1617+
expr_try_dynamic_cast<code_frontend_assignt>(op_code.op1()))
16181618
{
16191619
const code_assumet assumption{
16201620
typecheck_function_call_argument_rhs(tia_element, assignment->rhs())};
@@ -1660,7 +1660,7 @@ void statement_list_typecheckt::typecheck_called_function(
16601660
const code_typet &called_type{to_code_type(called_function_sym.type)};
16611661

16621662
// Check if function name is followed by data block.
1663-
if(!can_cast_expr<equal_exprt>(op_code.op1()))
1663+
if(!can_cast_expr<code_frontend_assignt>(op_code.op1()))
16641664
{
16651665
error() << "Function calls should not address instance data blocks" << eom;
16661666
throw TYPECHECK_ERROR;
@@ -1669,11 +1669,11 @@ void statement_list_typecheckt::typecheck_called_function(
16691669
// Check if function interface matches the call and fill argument list.
16701670
const code_typet::parameterst &params{called_type.parameters()};
16711671
code_function_callt::argumentst args;
1672-
std::vector<equal_exprt> assignments;
1672+
std::vector<code_frontend_assignt> assignments;
16731673
for(const auto &expr : op_code.operands())
16741674
{
1675-
if(can_cast_expr<equal_exprt>(expr))
1676-
assignments.push_back(to_equal_expr(expr));
1675+
if(auto assign = expr_try_dynamic_cast<code_frontend_assignt>(expr))
1676+
assignments.push_back(*assign);
16771677
}
16781678

16791679
for(const code_typet::parametert &param : params)
@@ -1706,13 +1706,13 @@ void statement_list_typecheckt::typecheck_called_function_block(
17061706
}
17071707

17081708
exprt statement_list_typecheckt::typecheck_function_call_arguments(
1709-
const std::vector<equal_exprt> &assignments,
1709+
const std::vector<code_frontend_assignt> &assignments,
17101710
const code_typet::parametert &param,
17111711
const symbolt &tia_element)
17121712
{
17131713
const irep_idt &param_name = param.get_base_name();
17141714
const typet &param_type = param.type();
1715-
for(const equal_exprt &assignment : assignments)
1715+
for(const auto &assignment : assignments)
17161716
{
17171717
const symbol_exprt &lhs{to_symbol_expr(assignment.lhs())};
17181718
if(param_name == lhs.get_identifier())
@@ -1752,11 +1752,11 @@ exprt statement_list_typecheckt::typecheck_function_call_argument_rhs(
17521752
}
17531753

17541754
exprt statement_list_typecheckt::typecheck_return_value_assignment(
1755-
const std::vector<equal_exprt> &assignments,
1755+
const std::vector<code_frontend_assignt> &assignments,
17561756
const typet &return_type,
17571757
const symbolt &tia_element)
17581758
{
1759-
for(const equal_exprt &assignment : assignments)
1759+
for(const auto &assignment : assignments)
17601760
{
17611761
const symbol_exprt &lhs{to_symbol_expr(assignment.lhs())};
17621762
if(ID_statement_list_return_value_id == lhs.get_identifier())

src/statement-list/statement_list_typecheck.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ class statement_list_typecheckt : public typecheckt
719719
/// \param tia_element: Symbol representation of the TIA element.
720720
/// \return Expression including the assigned symbol's name and type.
721721
exprt typecheck_function_call_arguments(
722-
const std::vector<equal_exprt> &assignments,
722+
const std::vector<code_frontend_assignt> &assignments,
723723
const code_typet::parametert &param,
724724
const symbolt &tia_element);
725725

@@ -740,7 +740,7 @@ class statement_list_typecheckt : public typecheckt
740740
/// \param tia_element: Symbol representation of the TIA element.
741741
/// \return Expression including the assigned symbol's name and type.
742742
exprt typecheck_return_value_assignment(
743-
const std::vector<equal_exprt> &assignments,
743+
const std::vector<code_frontend_assignt> &assignments,
744744
const typet &return_type,
745745
const symbolt &tia_element);
746746

src/util/std_expr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,7 @@ class equal_exprt:public binary_relation_exprt
13081308
equal_exprt(exprt _lhs, exprt _rhs)
13091309
: binary_relation_exprt(std::move(_lhs), ID_equal, std::move(_rhs))
13101310
{
1311+
PRECONDITION(lhs().type() == rhs().type());
13111312
}
13121313

13131314
static void check(

unit/analyses/variable-sensitivity/full_array_abstract_object/array_builder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ full_array_abstract_objectt::full_array_pointert build_array(
2929
{
3030
const typet type = signedbv_typet(32);
3131

32-
const array_typet array_type(
33-
integer_typet(), from_integer(array.size(), type));
32+
const array_typet array_type(type, from_integer(array.size(), type));
3433

3534
exprt::operandst element_ops;
3635

unit/goto-symex/try_evaluate_pointer_comparisons.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,14 @@ SCENARIO(
8080
}
8181
}
8282

83-
WHEN("Evaluating ptr1 == (long*)(short*)&value1")
83+
WHEN("Evaluating ptr1 == (int*)(short*)&value1")
8484
{
8585
const signedbv_typet long_type{64};
8686
const signedbv_typet short_type{16};
87-
const pointer_typet ptr_long_type = pointer_type(long_type);
8887
const pointer_typet ptr_short_type = pointer_type(short_type);
8988
const equal_exprt comparison{
9089
ptr1,
91-
typecast_exprt{typecast_exprt{address1, ptr_short_type},
92-
ptr_long_type}};
90+
typecast_exprt{typecast_exprt{address1, ptr_short_type}, ptr_type}};
9391
const renamedt<exprt, L2> renamed_comparison =
9492
state.rename(comparison, ns);
9593
auto result = try_evaluate_pointer_comparisons(

0 commit comments

Comments
 (0)