Skip to content

Commit f68d9f1

Browse files
Merge pull request #4827 from romainbrenguier/bugfix/symex-assign-symbol
Refactor and unit test symex_assign_symbol
2 parents 1bc4b21 + d929d34 commit f68d9f1

File tree

9 files changed

+467
-250
lines changed

9 files changed

+467
-250
lines changed

src/goto-symex/goto_symex.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ Author: Daniel Kroening, [email protected]
1010
/// Symbolic Execution
1111

1212
#include "goto_symex.h"
13+
#include "symex_assign.h"
1314

15+
#include <util/format_expr.h>
16+
#include <util/pointer_offset_size.h>
1417
#include <util/simplify_expr.h>
1518

1619
unsigned goto_symext::dynamic_counter=0;
@@ -20,3 +23,63 @@ void goto_symext::do_simplify(exprt &expr)
2023
if(symex_config.simplify_opt)
2124
simplify(expr, ns);
2225
}
26+
27+
void goto_symext::symex_assign(statet &state, const code_assignt &code)
28+
{
29+
exprt lhs = clean_expr(code.lhs(), state, true);
30+
exprt rhs = clean_expr(code.rhs(), state, false);
31+
32+
DATA_INVARIANT(
33+
lhs.type() == rhs.type(), "assignments must be type consistent");
34+
35+
log.conditional_output(
36+
log.debug(), [this, &lhs](messaget::mstreamt &mstream) {
37+
mstream << "Assignment to " << format(lhs) << " ["
38+
<< pointer_offset_bits(lhs.type(), ns).value_or(0) << " bits]"
39+
<< messaget::eom;
40+
});
41+
42+
if(rhs.id() == ID_side_effect)
43+
{
44+
const side_effect_exprt &side_effect_expr = to_side_effect_expr(rhs);
45+
const irep_idt &statement = side_effect_expr.get_statement();
46+
47+
if(
48+
statement == ID_cpp_new || statement == ID_cpp_new_array ||
49+
statement == ID_java_new_array_data)
50+
{
51+
symex_cpp_new(state, lhs, side_effect_expr);
52+
}
53+
else if(statement == ID_allocate)
54+
symex_allocate(state, lhs, side_effect_expr);
55+
else if(statement == ID_va_start)
56+
symex_va_start(state, lhs, side_effect_expr);
57+
else
58+
UNREACHABLE;
59+
}
60+
else
61+
{
62+
assignment_typet assignment_type = symex_targett::assignment_typet::STATE;
63+
64+
// Let's hide return value assignments.
65+
if(
66+
lhs.id() == ID_symbol &&
67+
id2string(to_symbol_expr(lhs).get_identifier()).find("#return_value!") !=
68+
std::string::npos)
69+
{
70+
assignment_type = symex_targett::assignment_typet::HIDDEN;
71+
}
72+
73+
// We hide if we are in a hidden function.
74+
if(state.call_stack().top().hidden_function)
75+
assignment_type = symex_targett::assignment_typet::HIDDEN;
76+
77+
// We hide if we are executing a hidden instruction.
78+
if(state.source.pc->source_location.get_hide())
79+
assignment_type = symex_targett::assignment_typet::HIDDEN;
80+
81+
exprt::operandst lhs_if_then_else_conditions;
82+
symex_assignt{state, assignment_type, ns, symex_config, target}.assign_rec(
83+
lhs, nil_exprt(), rhs, lhs_if_then_else_conditions);
84+
}
85+
}

src/goto-symex/goto_symex.h

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ class goto_symext
533533

534534
typedef symex_targett::assignment_typet assignment_typet;
535535

536-
/// Execute any let expressions in \p expr using \ref symex_assign_symbol.
536+
/// Execute any let expressions in \p expr using
537+
/// \ref symex_assignt::assign_symbol.
537538
/// The assignments will be made in bottom-up topological but otherwise
538539
/// arbitrary order (i.e. in `(let x = let y = 0 in x + y) + (let z = 0 in z)
539540
/// we will define `y` before `x`, but `z` and `x` could come in either order)
@@ -545,63 +546,6 @@ class goto_symext
545546
/// meaning it will be killed when \ref symex_step concludes.
546547
void lift_let(statet &state, const let_exprt &let_expr);
547548

548-
void symex_assign_rec(
549-
statet &,
550-
const exprt &lhs,
551-
const exprt &full_lhs,
552-
const exprt &rhs,
553-
exprt::operandst &,
554-
assignment_typet);
555-
void symex_assign_from_struct(
556-
statet &,
557-
const ssa_exprt &lhs,
558-
const exprt &full_lhs,
559-
const struct_exprt &rhs,
560-
const exprt::operandst &,
561-
assignment_typet);
562-
void symex_assign_symbol(
563-
statet &,
564-
const ssa_exprt &lhs,
565-
const exprt &full_lhs,
566-
const exprt &rhs,
567-
const exprt::operandst &,
568-
assignment_typet);
569-
void symex_assign_typecast(
570-
statet &,
571-
const typecast_exprt &lhs,
572-
const exprt &full_lhs,
573-
const exprt &rhs,
574-
exprt::operandst &,
575-
assignment_typet);
576-
void symex_assign_array(
577-
statet &,
578-
const index_exprt &lhs,
579-
const exprt &full_lhs,
580-
const exprt &rhs,
581-
exprt::operandst &,
582-
assignment_typet);
583-
void symex_assign_struct_member(
584-
statet &,
585-
const member_exprt &lhs,
586-
const exprt &full_lhs,
587-
const exprt &rhs,
588-
exprt::operandst &,
589-
assignment_typet);
590-
void symex_assign_if(
591-
statet &,
592-
const if_exprt &lhs,
593-
const exprt &full_lhs,
594-
const exprt &rhs,
595-
exprt::operandst &,
596-
assignment_typet);
597-
void symex_assign_byte_extract(
598-
statet &,
599-
const byte_extract_exprt &lhs,
600-
const exprt &full_lhs,
601-
const exprt &rhs,
602-
exprt::operandst &,
603-
assignment_typet);
604-
605549
virtual void
606550
symex_va_start(statet &, const exprt &lhs, const side_effect_exprt &);
607551

0 commit comments

Comments
 (0)