CBMC
insert_final_assert_false.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Insert assert(false) at end of entry function
4 
5 Author: Nathan Chong, Kareem Khazem
6 
7 \*******************************************************************/
8 
11 
13 
15 #include <util/irep.h>
16 
17 #include <iterator>
18 #include <list>
19 
21  message_handlert &_message_handler)
22  : log(_message_handler)
23 {
24 }
25 
27 operator()(goto_modelt &goto_model, const std::string &function_to_instrument)
28 {
29  const irep_idt entry(function_to_instrument);
30  auto it = goto_model.goto_functions.function_map.find(entry);
31  if(it == goto_model.goto_functions.function_map.end())
32  {
33  log.error() << "insert-final-assert-false: could not find function "
34  << "'" << function_to_instrument << "'" << messaget::eom;
35  return true;
36  }
37  goto_programt &entry_function = (it->second).body;
38  goto_programt::instructionst &instructions = entry_function.instructions;
39  auto instr_it = instructions.end();
40  auto last_instruction = std::prev(instr_it);
42  last_instruction->is_end_function(),
43  "last instruction in function should be END_FUNCTION");
44  source_locationt assert_location = last_instruction->source_location();
45  assert_location.set_property_class(ID_assertion);
46  assert_location.set_comment("insert-final-assert-false (should fail) ");
47  goto_programt::instructiont false_assert =
48  goto_programt::make_assertion(false_exprt(), assert_location);
49  entry_function.insert_before_swap(last_instruction, false_assert);
50  return false;
51 }
52 
54  goto_modelt &goto_model,
55  const std::string &function_to_instrument,
56  message_handlert &message_handler)
57 {
58  insert_final_assert_falset ifaf(message_handler);
59  return ifaf(goto_model, function_to_instrument);
60 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
source_locationt::set_comment
void set_comment(const irep_idt &comment)
Definition: source_location.h:135
goto_programt::instructionst
std::list< instructiont > instructionst
Definition: goto_program.h:584
goto_model.h
goto_modelt
Definition: goto_model.h:25
insert_final_assert_false.h
messaget::eom
static eomt eom
Definition: message.h:297
insert_final_assert_falset::insert_final_assert_falset
insert_final_assert_falset(message_handlert &_message_handler)
Definition: insert_final_assert_false.cpp:20
goto_functionst::function_map
function_mapt function_map
Definition: goto_functions.h:29
goto_programt::make_assertion
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
Definition: goto_program.h:924
messaget::error
mstreamt & error() const
Definition: message.h:399
insert_final_assert_falset
Definition: insert_final_assert_false.h:26
DATA_INVARIANT
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition: invariant.h:510
message_handlert
Definition: message.h:27
insert_final_assert_falset::operator()
bool operator()(goto_modelt &, const std::string &)
Definition: insert_final_assert_false.cpp:27
false_exprt
The Boolean constant false.
Definition: std_expr.h:3016
source_locationt
Definition: source_location.h:18
goto_programt::instructions
instructionst instructions
The list of instructions in the goto program.
Definition: goto_program.h:592
goto_modelt::goto_functions
goto_functionst goto_functions
GOTO functions.
Definition: goto_model.h:33
insert_final_assert_falset::log
messaget log
Definition: insert_final_assert_false.h:33
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:72
insert_final_assert_false
bool insert_final_assert_false(goto_modelt &goto_model, const std::string &function_to_instrument, message_handlert &message_handler)
Transform a goto program by inserting assert(false) at the end of a given function function_to_instru...
Definition: insert_final_assert_false.cpp:53
goto_programt::insert_before_swap
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
Definition: goto_program.h:613
goto_programt::instructiont
This class represents an instruction in the GOTO intermediate representation.
Definition: goto_program.h:180
irep.h
source_locationt::set_property_class
void set_property_class(const irep_idt &property_class)
Definition: source_location.h:130