Skip to content

Commit 0f108e3

Browse files
Fault localizer for goto-symex
Requires prop_convt, symex_target_equationt and frozen guards.
1 parent 35fbdab commit 0f108e3

File tree

3 files changed

+214
-0
lines changed

3 files changed

+214
-0
lines changed

src/goto-checker/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SRC = bmc_util.cpp \
22
counterexample_beautification.cpp \
33
cover_goals_report_util.cpp \
44
incremental_goto_checker.cpp \
5+
goto_symex_fault_localizer.cpp \
56
goto_symex_property_decider.cpp \
67
goto_trace_storage.cpp \
78
goto_verifier.cpp \
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*******************************************************************\
2+
3+
Module: Fault Localization for Goto Symex
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Fault Localization for Goto Symex
11+
12+
#include "goto_symex_fault_localizer.h"
13+
14+
#include <solvers/prop/prop_conv.h>
15+
16+
goto_symex_fault_localizert::goto_symex_fault_localizert(
17+
const optionst &options,
18+
ui_message_handlert &ui_message_handler,
19+
const symex_target_equationt &equation,
20+
prop_convt &solver)
21+
: options(options),
22+
ui_message_handler(ui_message_handler),
23+
equation(equation),
24+
solver(solver)
25+
{
26+
}
27+
28+
fault_location_infot goto_symex_fault_localizert::
29+
operator()(const irep_idt &failed_property_id)
30+
{
31+
fault_location_infot fault_location;
32+
localization_pointst localization_points;
33+
const auto &failed_step =
34+
collect_guards(failed_property_id, localization_points, fault_location);
35+
36+
if(!localization_points.empty())
37+
{
38+
messaget log(ui_message_handler);
39+
log.status() << "Localizing fault" << messaget::eom;
40+
41+
// pick localization method
42+
// if(options.get_option("localize-faults-method")=="TBD")
43+
localize_linear(failed_step, localization_points);
44+
}
45+
46+
return fault_location;
47+
}
48+
49+
const symex_target_equationt::SSA_stept &
50+
goto_symex_fault_localizert::collect_guards(
51+
const irep_idt &failed_property_id,
52+
localization_pointst &localization_points,
53+
fault_location_infot &fault_location)
54+
{
55+
for(const auto &step : equation.SSA_steps)
56+
{
57+
if(
58+
step.is_assignment() &&
59+
step.assignment_type == symex_targett::assignment_typet::STATE &&
60+
!step.ignore)
61+
{
62+
if(!step.guard_literal.is_constant())
63+
{
64+
auto emplace_result = fault_location.scores.emplace(step.source.pc, 0);
65+
localization_points.emplace(step.guard_literal, emplace_result.first);
66+
}
67+
}
68+
69+
// reached failed assertion?
70+
if(step.is_assert() && step.get_property_id() == failed_property_id)
71+
return step;
72+
}
73+
UNREACHABLE;
74+
}
75+
76+
bool goto_symex_fault_localizert::check(
77+
const symex_target_equationt::SSA_stept &failed_step,
78+
const localization_pointst &localization_points,
79+
const localization_points_valuet &value)
80+
{
81+
PRECONDITION(value.size() == localization_points.size());
82+
bvt assumptions;
83+
localization_points_valuet::const_iterator v_it = value.begin();
84+
for(const auto &l : localization_points)
85+
{
86+
if(v_it->is_true())
87+
assumptions.push_back(l.first);
88+
else if(v_it->is_false())
89+
assumptions.push_back(!l.first);
90+
++v_it;
91+
}
92+
93+
// lock the failed assertion
94+
assumptions.push_back(!failed_step.cond_literal);
95+
96+
solver.set_assumptions(assumptions);
97+
98+
if(solver() == decision_proceduret::resultt::D_SATISFIABLE)
99+
return false;
100+
101+
return true;
102+
}
103+
104+
void goto_symex_fault_localizert::update_scores(
105+
const localization_pointst &localization_points)
106+
{
107+
for(auto &l : localization_points)
108+
{
109+
if(solver.l_get(l.first).is_true())
110+
{
111+
l.second->second++;
112+
}
113+
else if(solver.l_get(l.first).is_false() && l.second->second > 0)
114+
{
115+
l.second->second--;
116+
}
117+
}
118+
}
119+
120+
void goto_symex_fault_localizert::localize_linear(
121+
const symex_target_equationt::SSA_stept &failed_step,
122+
const localization_pointst &localization_points)
123+
{
124+
localization_points_valuet v;
125+
v.resize(localization_points.size());
126+
127+
for(std::size_t i = 0; i < localization_points.size(); ++i)
128+
v[i] = tvt(tvt::tv_enumt::TV_UNKNOWN);
129+
130+
for(std::size_t i = 0; i < v.size(); ++i)
131+
{
132+
v[i] = tvt(tvt::tv_enumt::TV_TRUE);
133+
if(!check(failed_step, localization_points, v))
134+
update_scores(localization_points);
135+
136+
v[i] = tvt(tvt::tv_enumt::TV_FALSE);
137+
if(!check(failed_step, localization_points, v))
138+
update_scores(localization_points);
139+
140+
v[i] = tvt(tvt::tv_enumt::TV_UNKNOWN);
141+
}
142+
143+
// clear assumptions
144+
bvt assumptions;
145+
solver.set_assumptions(assumptions);
146+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*******************************************************************\
2+
3+
Module: Fault Localization for Goto Symex
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Fault Localization for Goto Symex
11+
12+
#ifndef CPROVER_GOTO_CHECKER_GOTO_SYMEX_FAULT_LOCALIZER_H
13+
#define CPROVER_GOTO_CHECKER_GOTO_SYMEX_FAULT_LOCALIZER_H
14+
15+
#include <util/options.h>
16+
#include <util/threeval.h>
17+
#include <util/ui_message.h>
18+
19+
#include <goto-symex/symex_target_equation.h>
20+
21+
#include "fault_localization_provider.h"
22+
23+
class goto_symex_fault_localizert
24+
{
25+
public:
26+
goto_symex_fault_localizert(
27+
const optionst &options,
28+
ui_message_handlert &ui_message_handler,
29+
const symex_target_equationt &equation,
30+
prop_convt &solver);
31+
32+
fault_location_infot operator()(const irep_idt &failed_property_id);
33+
34+
protected:
35+
const optionst &options;
36+
ui_message_handlert &ui_message_handler;
37+
const symex_target_equationt &equation;
38+
prop_convt &solver;
39+
40+
/// A localization point is a goto instruction that is potentially at fault
41+
typedef std::map<literalt, fault_location_infot::score_mapt::iterator>
42+
localization_pointst;
43+
44+
/// Collects the guards as \p localization_points up to \p failed_property_id
45+
/// and initializes fault_location_info, and returns the SSA step of
46+
/// the failed property
47+
const symex_target_equationt::SSA_stept &collect_guards(
48+
const irep_idt &failed_property_id,
49+
localization_pointst &localization_points,
50+
fault_location_infot &fault_location);
51+
52+
// specify a localization point combination to check
53+
typedef std::vector<tvt> localization_points_valuet;
54+
bool check(
55+
const symex_target_equationt::SSA_stept &failed_step,
56+
const localization_pointst &,
57+
const localization_points_valuet &);
58+
59+
void update_scores(const localization_pointst &);
60+
61+
// localization method: flip each point
62+
void localize_linear(
63+
const symex_target_equationt::SSA_stept &failed_step,
64+
const localization_pointst &);
65+
};
66+
67+
#endif // CPROVER_GOTO_CHECKER_GOTO_SYMEX_FAULT_LOCALIZER_H

0 commit comments

Comments
 (0)