Skip to content

Commit 0c2b8dd

Browse files
committed
Don't generate unnecessary fresh symbols for the GOTO trace
We can safely record the values of expressions by adding `expr == expr` as constraints in order to be able to fetch and display them in the GOTO trace. This was already being done for declarations. Introducing new symbols just adds unnecessary variables to the formula.
1 parent c5b30b8 commit 0c2b8dd

File tree

4 files changed

+27
-66
lines changed

4 files changed

+27
-66
lines changed

regression/cbmc-incr-smt2/pointers-conversions/pointer_to_int.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
KNOWNBUG
22
pointer_to_int.c
33
--trace
44
\[main\.assertion\.1\] line \d+ expected result == -1: success: SUCCESS

src/goto-symex/build_goto_trace.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,12 @@ void build_goto_trace(
351351
goto_trace_step.io_id = SSA_step.io_id;
352352
goto_trace_step.formatted = SSA_step.formatted;
353353
goto_trace_step.called_function = SSA_step.called_function;
354-
goto_trace_step.function_arguments = SSA_step.converted_function_arguments;
355354

356-
for(auto &arg : goto_trace_step.function_arguments)
357-
arg = decision_procedure.get(arg);
355+
for(const auto &arg : SSA_step.converted_function_arguments)
356+
{
357+
goto_trace_step.function_arguments.push_back(
358+
simplify_expr(decision_procedure.get(arg), ns));
359+
}
358360

359361
// update internal field for specific variables in the counterexample
360362
update_internal_field(SSA_step, goto_trace_step, ns);
@@ -391,15 +393,8 @@ void build_goto_trace(
391393

392394
for(const auto &j : SSA_step.converted_io_args)
393395
{
394-
if(j.is_constant() || j.id() == ID_string_constant)
395-
{
396-
goto_trace_step.io_args.push_back(j);
397-
}
398-
else
399-
{
400-
exprt tmp = decision_procedure.get(j);
401-
goto_trace_step.io_args.push_back(tmp);
402-
}
396+
goto_trace_step.io_args.push_back(
397+
simplify_expr(decision_procedure.get(j), ns));
403398
}
404399

405400
if(SSA_step.is_assert() || SSA_step.is_assume() || SSA_step.is_goto())

src/goto-symex/symex_target_equation.cpp

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -620,33 +620,18 @@ void symex_target_equationt::convert_function_calls(
620620
{
621621
if(!step.ignore)
622622
{
623-
and_exprt::operandst conjuncts;
624623
step.converted_function_arguments.reserve(step.ssa_function_arguments.size());
625624

626625
for(const auto &arg : step.ssa_function_arguments)
627626
{
628-
if(arg.is_constant() ||
629-
arg.id()==ID_string_constant)
630-
step.converted_function_arguments.push_back(arg);
631-
else
627+
if(!arg.is_constant() && arg.id() != ID_string_constant)
632628
{
633-
const irep_idt identifier="symex::args::"+std::to_string(argument_count++);
634-
symbol_exprt symbol(identifier, arg.type());
635-
636-
equal_exprt eq(arg, symbol);
629+
equal_exprt eq{arg, arg};
637630
merge_irep(eq);
638-
639-
decision_procedure.set_to(eq, true);
640-
conjuncts.push_back(eq);
641-
step.converted_function_arguments.push_back(symbol);
631+
decision_procedure.set_to_true(eq);
642632
}
633+
step.converted_function_arguments.push_back(arg);
643634
}
644-
with_solver_hardness(
645-
decision_procedure,
646-
[step_index, &conjuncts, &step](solver_hardnesst &hardness) {
647-
hardness.register_ssa(
648-
step_index, conjunction(conjuncts), step.source.pc);
649-
});
650635
}
651636
++step_index;
652637
}
@@ -659,32 +644,16 @@ void symex_target_equationt::convert_io(decision_proceduret &decision_procedure)
659644
{
660645
if(!step.ignore)
661646
{
662-
and_exprt::operandst conjuncts;
663647
for(const auto &arg : step.io_args)
664648
{
665-
if(arg.is_constant() ||
666-
arg.id()==ID_string_constant)
667-
step.converted_io_args.push_back(arg);
668-
else
649+
if(!arg.is_constant() && arg.id() != ID_string_constant)
669650
{
670-
const irep_idt identifier =
671-
"symex::io::" + std::to_string(io_count++);
672-
symbol_exprt symbol(identifier, arg.type());
673-
674-
equal_exprt eq(arg, symbol);
651+
equal_exprt eq{arg, arg};
675652
merge_irep(eq);
676-
677-
decision_procedure.set_to(eq, true);
678-
conjuncts.push_back(eq);
679-
step.converted_io_args.push_back(symbol);
653+
decision_procedure.set_to_true(eq);
680654
}
655+
step.converted_io_args.push_back(arg);
681656
}
682-
with_solver_hardness(
683-
decision_procedure,
684-
[step_index, &conjuncts, &step](solver_hardnesst &hardness) {
685-
hardness.register_ssa(
686-
step_index, conjunction(conjuncts), step.source.pc);
687-
});
688657
}
689658
++step_index;
690659
}

src/solvers/smt2/smt2_conv.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,6 @@ exprt smt2_convt::get(const exprt &expr) const
297297
if(it!=identifier_map.end())
298298
return it->second.value;
299299
}
300-
else if(expr.id()==ID_member)
301-
{
302-
const member_exprt &member_expr=to_member_expr(expr);
303-
exprt tmp=get(member_expr.struct_op());
304-
if(tmp.is_nil())
305-
return nil_exprt();
306-
return member_exprt(tmp, member_expr.get_component_name(), expr.type());
307-
}
308300
else if(expr.id() == ID_literal)
309301
{
310302
auto l = to_literal_expr(expr).get_literal();
@@ -323,14 +315,17 @@ exprt smt2_convt::get(const exprt &expr) const
323315
}
324316
else if(expr.is_constant())
325317
return expr;
326-
else if(const auto &array = expr_try_dynamic_cast<array_exprt>(expr))
318+
else if(expr.has_operands())
327319
{
328-
exprt array_copy = *array;
329-
for(auto &element : array_copy.operands())
320+
exprt copy = expr;
321+
for(auto &op : copy.operands())
330322
{
331-
element = get(element);
323+
exprt eval_op = get(op);
324+
if(eval_op.is_nil())
325+
return nil_exprt{};
326+
op = std::move(eval_op);
332327
}
333-
return array_copy;
328+
return copy;
334329
}
335330

336331
return nil_exprt();
@@ -4641,7 +4636,9 @@ void smt2_convt::set_to(const exprt &expr, bool value)
46414636
const irep_idt &identifier=
46424637
to_symbol_expr(equal_expr.lhs()).get_identifier();
46434638

4644-
if(identifier_map.find(identifier)==identifier_map.end())
4639+
if(
4640+
identifier_map.find(identifier) == identifier_map.end() &&
4641+
equal_expr.lhs() != equal_expr.rhs())
46454642
{
46464643
identifiert &id=identifier_map[identifier];
46474644
CHECK_RETURN(id.type.is_nil());

0 commit comments

Comments
 (0)