cprover
cover_instrument_other.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Coverage Instrumentation
4 
5 Author: Daniel Kroening
6 
7 \*******************************************************************/
8 
11 
12 #include "cover_instrument.h"
13 
14 #include <langapi/language_util.h>
15 
16 #include "cover_util.h"
17 
19  const irep_idt &,
20  goto_programt &,
22  const cover_blocks_baset &) const
23 {
24  if(is_non_cover_assertion(i_it))
25  i_it->turn_into_skip();
26 
27  // TODO: implement
28 }
29 
31  const irep_idt &function_id,
32  goto_programt &,
34  const cover_blocks_baset &) const
35 {
36  // turn into 'assert(false)' to avoid simplification
37  if(is_non_cover_assertion(i_it))
38  {
39  i_it->guard = false_exprt();
41  i_it, id2string(i_it->source_location.get_comment()), function_id);
42  }
43 }
44 
46  const irep_idt &function_id,
47  goto_programt &,
49  const cover_blocks_baset &) const
50 {
51  // turn __CPROVER_cover(x) into 'assert(!x)'
52  if(i_it->is_function_call())
53  {
54  const code_function_callt &code_function_call =
55  to_code_function_call(i_it->code);
56  if(
57  code_function_call.function().id() == ID_symbol &&
58  to_symbol_expr(code_function_call.function()).get_identifier() ==
59  CPROVER_PREFIX "cover" &&
60  code_function_call.arguments().size() == 1)
61  {
62  const exprt c = code_function_call.arguments()[0];
63  std::string comment = "condition '" + from_expr(ns, function_id, c) + "'";
64  i_it->guard = not_exprt(c);
65  i_it->type = ASSERT;
66  i_it->code.clear();
67  initialize_source_location(i_it, comment, function_id);
68  }
69  }
70  else if(is_non_cover_assertion(i_it))
71  i_it->turn_into_skip();
72 }
73 
75  const irep_idt &function_id,
76  goto_programt &goto_program)
77 {
78  const auto last_function_call = std::find_if(
79  goto_program.instructions.rbegin(),
80  goto_program.instructions.rend(),
81  [](const goto_programt::instructiont &instruction) {
82  return instruction.is_function_call();
83  });
84  INVARIANT(
85  last_function_call != goto_program.instructions.rend(),
86  "Goto program should have at least one function call");
87  INVARIANT(
88  last_function_call != goto_program.instructions.rbegin(),
89  "Goto program shouldn't end with a function call");
90  const auto if_it = last_function_call.base();
91  const std::string &comment =
92  "additional goal to ensure reachability of end of function";
93  goto_program.insert_before_swap(if_it);
95  if_it->source_location.set_comment(comment);
96  if_it->source_location.set_property_class("reachability_constraint");
97  if_it->source_location.set_function(function_id);
98 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
cover_instrumenter_baset::is_non_cover_assertion
bool is_non_cover_assertion(goto_programt::const_targett t) const
Definition: cover_instrument.h:79
cover_instrumenter_baset::initialize_source_location
void initialize_source_location(goto_programt::targett t, const std::string &comment, const irep_idt &function_id) const
Definition: cover_instrument.h:68
cover_instrumenter_baset::ns
const namespacet ns
Definition: cover_instrument.h:58
exprt
Base class for all expressions.
Definition: expr.h:53
code_function_callt
codet representation of a function call statement.
Definition: std_code.h:1186
goto_programt::make_assertion
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:893
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
language_util.h
cover_instrument.h
cover_instrument_end_of_function
void cover_instrument_end_of_function(const irep_idt &function_id, goto_programt &goto_program)
Definition: cover_instrument_other.cpp:74
symbol_exprt::get_identifier
const irep_idt & get_identifier() const
Definition: std_expr.h:111
cover_assertion_instrumentert::instrument
void instrument(const irep_idt &function_id, goto_programt &, goto_programt::targett &, const cover_blocks_baset &) const override
Override this method to implement an instrumenter.
Definition: cover_instrument_other.cpp:30
cover_blocks_baset
Definition: cover_basic_blocks.h:24
to_symbol_expr
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition: std_expr.h:177
irept::id
const irep_idt & id() const
Definition: irep.h:418
to_code_function_call
const code_function_callt & to_code_function_call(const codet &code)
Definition: std_code.h:1297
false_exprt
The Boolean constant false.
Definition: std_expr.h:3993
code_function_callt::arguments
argumentst & arguments()
Definition: std_code.h:1231
goto_programt::instructions
instructionst instructions
The list of instructions in the goto program.
Definition: goto_program.h:585
cover_cover_instrumentert::instrument
void instrument(const irep_idt &function_id, goto_programt &, goto_programt::targett &, const cover_blocks_baset &) const override
Override this method to implement an instrumenter.
Definition: cover_instrument_other.cpp:45
CPROVER_PREFIX
#define CPROVER_PREFIX
Definition: cprover_prefix.h:14
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:73
cover_path_instrumentert::instrument
void instrument(const irep_idt &function_id, goto_programt &, goto_programt::targett &, const cover_blocks_baset &) const override
Override this method to implement an instrumenter.
Definition: cover_instrument_other.cpp:18
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:424
goto_programt::insert_before_swap
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
Definition: goto_program.h:606
cover_util.h
ASSERT
@ ASSERT
Definition: goto_program.h:36
comment
static std::string comment(const rw_set_baset::entryt &entry, bool write)
Definition: race_check.cpp:109
goto_programt::instructiont
This class represents an instruction in the GOTO intermediate representation.
Definition: goto_program.h:179
from_expr
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
Definition: language_util.cpp:20
goto_programt::targett
instructionst::iterator targett
Definition: goto_program.h:579
code_function_callt::function
exprt & function()
Definition: std_code.h:1221
not_exprt
Boolean negation.
Definition: std_expr.h:2872