Skip to content

Commit c106b08

Browse files
authored
Merge pull request #7507 from peterschrammel/solver-stats-bug
Fix bug in solver hardness stats
2 parents 9b19704 + 52c3eed commit c106b08

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

regression/solver-hardness/solver-hardness-simple/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ int main()
55
int a;
66
int b;
77
assert(a + b < 10);
8+
assert(a < 10);
89
return 0;
910
}

regression/solver-hardness/solver-hardness-simple/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ main.c
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
77
\"SAT_hardness\":\{(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+)\}
8+
\"GOTO_ID\":32,\"SAT_hardness\":\{\"ClauseSet\":\[.*,571\],\"Clauses\":571
89
--
910
^warning: ignoring

src/goto-checker/goto_symex_property_decider.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, Peter Schrammel
1313

1414
#include <util/ui_message.h>
1515

16+
#include <goto-symex/solver_hardness.h>
1617
#include <solvers/prop/prop.h> // IWYU pragma: keep
1718

1819
goto_symex_property_decidert::goto_symex_property_decidert(
@@ -83,6 +84,7 @@ void goto_symex_property_decidert::add_constraint_from_goals(
8384
std::function<bool(const irep_idt &)> select_property)
8485
{
8586
exprt::operandst disjuncts;
87+
decision_proceduret &decision_procedure = solver->decision_procedure();
8688

8789
for(const auto &goal_pair : goal_map)
8890
{
@@ -95,7 +97,16 @@ void goto_symex_property_decidert::add_constraint_from_goals(
9597
}
9698

9799
// this is 'false' if there are no disjuncts
98-
solver->decision_procedure().set_to_true(disjunction(disjuncts));
100+
exprt goal_disjunction = disjunction(disjuncts);
101+
decision_procedure.set_to_true(goal_disjunction);
102+
103+
with_solver_hardness(decision_procedure, [](solver_hardnesst &hardness) {
104+
// SSA expr and involved steps have already been collected
105+
// in symex_target_equationt::convert_assertions
106+
exprt ssa_expr_unused;
107+
std::vector<goto_programt::const_targett> involved_steps_unused;
108+
hardness.register_assertion_ssas(ssa_expr_unused, involved_steps_unused);
109+
});
99110
}
100111

101112
decision_proceduret::resultt goto_symex_property_decidert::solve()

src/goto-symex/solver_hardness.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool solver_hardnesst::assertion_statst::empty() const
4444

4545
void solver_hardnesst::register_ssa(
4646
std::size_t ssa_index,
47-
const exprt ssa_expression,
47+
const exprt &ssa_expression,
4848
goto_programt::const_targett pc)
4949
{
5050
PRECONDITION(ssa_index < hardness_stats.size());
@@ -73,15 +73,16 @@ void solver_hardnesst::register_ssa_size(std::size_t size)
7373
}
7474

7575
void solver_hardnesst::register_assertion_ssas(
76-
const exprt ssa_expression,
76+
const exprt &ssa_expression,
7777
const std::vector<goto_programt::const_targett> &pcs)
7878
{
7979
if(assertion_stats.empty())
80-
return;
80+
{
81+
assertion_stats.ssa_expression = expr2string(ssa_expression);
82+
assertion_stats.pcs = pcs;
83+
}
8184

82-
assertion_stats.sat_hardness = current_hardness;
83-
assertion_stats.ssa_expression = expr2string(ssa_expression);
84-
assertion_stats.pcs = pcs;
85+
assertion_stats.sat_hardness += current_hardness;
8586
current_ssa_key = {};
8687
current_hardness = {};
8788
}
@@ -378,7 +379,7 @@ solver_hardnesst::goto_instruction2string(goto_programt::const_targett pc)
378379
return out.str();
379380
}
380381

381-
std::string solver_hardnesst::expr2string(const exprt expr)
382+
std::string solver_hardnesst::expr2string(const exprt &expr)
382383
{
383384
std::stringstream ss;
384385
ss << format(expr);

src/goto-symex/solver_hardness.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct solver_hardnesst : public clause_hardness_collectort
8282
/// \param pc: the GOTO instruction iterator for this SSA step
8383
void register_ssa(
8484
std::size_t ssa_index,
85-
const exprt ssa_expression,
85+
const exprt &ssa_expression,
8686
goto_programt::const_targett pc);
8787

8888
void register_ssa_size(std::size_t size);
@@ -95,7 +95,7 @@ struct solver_hardnesst : public clause_hardness_collectort
9595
/// \param pcs: all GOTO instruction iterators that contributed in the
9696
/// disjunction
9797
void register_assertion_ssas(
98-
const exprt ssa_expression,
98+
const exprt &ssa_expression,
9999
const std::vector<goto_programt::const_targett> &pcs);
100100

101101
/// Called e.g. from the `satcheck_minisat2::lcnf`, this function adds the
@@ -130,7 +130,7 @@ struct solver_hardnesst : public clause_hardness_collectort
130130
// A minor modification of \ref goto_programt::output_instruction
131131
static std::string goto_instruction2string(goto_programt::const_targett pc);
132132

133-
static std::string expr2string(const exprt expr);
133+
static std::string expr2string(const exprt &expr);
134134

135135
std::string outfile;
136136
std::vector<std::unordered_map<hardness_ssa_keyt, sat_hardnesst>>

0 commit comments

Comments
 (0)