|
| 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 | +} |
0 commit comments