|
| 1 | +/// \file cover_instrument_assume.cpp |
| 2 | +/// Author: Diffblue Ltd. |
| 3 | +/// Coverage Instrumentation for ASSUME instructions. |
| 4 | + |
| 5 | +#include "cover_instrument.h" |
| 6 | + |
| 7 | +#include "ansi-c/expr2c.h" |
| 8 | +#include "goto-programs/goto_program.h" |
| 9 | +#include "util/std_expr.h" |
| 10 | +#include <util/namespace.h> |
| 11 | + |
| 12 | +/// Instrument program to check coverage of assume statements. |
| 13 | +/// \param function_id The name of the function under instrumentation. |
| 14 | +/// \param goto_program The goto-program (function under instrumentation). |
| 15 | +/// \param i_it The current instruction (instruction under instrumentation). |
| 16 | +/// \param make_assertion The assertion generator function. |
| 17 | +void cover_assume_instrumentert::instrument( |
| 18 | + const irep_idt &function_id, |
| 19 | + goto_programt &goto_program, |
| 20 | + goto_programt::targett &i_it, |
| 21 | + const cover_blocks_baset &, |
| 22 | + const assertion_factoryt &make_assertion) const |
| 23 | +{ |
| 24 | + if(i_it->is_assume()) |
| 25 | + { |
| 26 | + const auto location = i_it->source_location; |
| 27 | + const auto assume_condition = |
| 28 | + expr2c(i_it->get_condition(), namespacet{symbol_tablet()}); |
| 29 | + const auto comment_before = |
| 30 | + "assert(false) before assume(" + assume_condition + ")"; |
| 31 | + const auto comment_after = |
| 32 | + "assert(false) after assume(" + assume_condition + ")"; |
| 33 | + |
| 34 | + const auto assert_before = make_assertion(false_exprt{}, location); |
| 35 | + goto_programt::targett t = goto_program.insert_before(i_it, assert_before); |
| 36 | + initialize_source_location(t, comment_before, function_id); |
| 37 | + |
| 38 | + const auto assert_after = make_assertion(false_exprt{}, location); |
| 39 | + t = goto_program.insert_after(i_it, assert_after); |
| 40 | + initialize_source_location(t, comment_after, function_id); |
| 41 | + } |
| 42 | + // Otherwise, skip existing assertions. |
| 43 | + else if(i_it->is_assert()) |
| 44 | + { |
| 45 | + const auto location = i_it->source_location; |
| 46 | + // Filter based on if assertion was added by us as part of instrumentation. |
| 47 | + if(location.get_property_class() != "coverage") |
| 48 | + { |
| 49 | + i_it->turn_into_skip(); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments