cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
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
12
#include "
insert_final_assert_false.h
"
13
14
#include <
goto-programs/goto_model.h
>
15
#include <
util/irep.h
>
16
17
#include <iterator>
18
#include <list>
19
20
insert_final_assert_falset::insert_final_assert_falset
(
21
message_handlert
&_message_handler)
22
:
log
(_message_handler)
23
{
24
}
25
26
bool
insert_final_assert_falset::
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);
41
DATA_INVARIANT
(
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
53
bool
insert_final_assert_false
(
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
}
false_exprt
The Boolean constant false.
Definition
std_expr.h:3125
goto_functionst::function_map
function_mapt function_map
Definition
goto_functions.h:29
goto_modelt
Definition
goto_model.h:27
goto_modelt::goto_functions
goto_functionst goto_functions
GOTO functions.
Definition
goto_model.h:34
goto_programt::instructiont
This class represents an instruction in the GOTO intermediate representation.
Definition
goto_program.h:180
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition
goto_program.h:72
goto_programt::instructions
instructionst instructions
The list of instructions in the goto program.
Definition
goto_program.h:621
goto_programt::insert_before_swap
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
Definition
goto_program.h:642
goto_programt::instructionst
std::list< instructiont > instructionst
Definition
goto_program.h:611
goto_programt::make_assertion
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
Definition
goto_program.h:932
insert_final_assert_falset
Definition
insert_final_assert_false.h:27
insert_final_assert_falset::log
messaget log
Definition
insert_final_assert_false.h:33
insert_final_assert_falset::operator()
bool operator()(goto_modelt &, const std::string &)
Definition
insert_final_assert_false.cpp:27
insert_final_assert_falset::insert_final_assert_falset
insert_final_assert_falset(message_handlert &_message_handler)
Definition
insert_final_assert_false.cpp:20
message_handlert
Definition
message.h:27
messaget::eom
static eomt eom
Definition
message.h:289
source_locationt
Definition
source_location.h:20
source_locationt::set_comment
void set_comment(const irep_idt &comment)
Definition
source_location.h:156
source_locationt::set_property_class
void set_property_class(const irep_idt &property_class)
Definition
source_location.h:151
goto_model.h
Symbol Table + CFG.
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
insert_final_assert_false.h
Insert final assert false into a function.
irep.h
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:534
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
goto-instrument
insert_final_assert_false.cpp
Generated by
1.17.0