| 113 | using print_var_val_ty = function<void(ostream&, const Model&)>; |
| 114 | |
| 115 | static bool error(Errors &errs, State &src_state, State &tgt_state, |
| 116 | const Result &r, Solver &solver, const Value *var, |
| 117 | const char *msg, bool check_each_var, |
| 118 | print_var_val_ty print_var_val) { |
| 119 | |
| 120 | if (r.isInvalid()) { |
| 121 | errs.add("Invalid expr", false); |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | if (r.isTimeout()) { |
| 126 | errs.add("Timeout", false); |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | if (r.isError()) { |
| 131 | errs.add("SMT Error: " + r.getReason(), false); |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | if (r.isSkip()) { |
| 136 | errs.add("Skip", false); |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | stringstream s; |
| 141 | string empty; |
| 142 | auto &var_name = var ? var->getName() : empty; |
| 143 | |
| 144 | { |
| 145 | // filter out approximations that don't contribute to the bug |
| 146 | // i.e., they don't show up in the SMT model |
| 147 | auto &m = r.getModel(); |
| 148 | set<string> approx; |
| 149 | for (auto *v : { &src_state.getApproximations(), |
| 150 | &tgt_state.getApproximations() }) { |
| 151 | for (auto &[msg, var] : *v) { |
| 152 | if (!var || m.hasFnModel(*var) || var->isConst()) |
| 153 | approx.emplace(msg); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | if (!approx.empty()) { |
| 158 | s << "Couldn't prove the correctness of the transformation\n" |
| 159 | "Alive2 approximated the semantics of the programs and therefore we\n" |
| 160 | "cannot conclude whether the bug found is valid or not.\n\n" |
| 161 | "Approximations done:\n"; |
| 162 | for (auto &msg : approx) { |
| 163 | s << " - " << msg << '\n'; |
| 164 | } |
| 165 | errs.add(std::move(s).str(), false); |
| 166 | return false; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | if (config::quiet) { |
| 171 | s << msg << " in " << src_state.getFn().getName() << '\n'; |
| 172 | errs.add(std::move(s).str(), true); |
no test coverage detected