cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
havoc_loops.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Havoc Loops
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
11
12
#include "
havoc_loops.h
"
13
14
#include <
analyses/natural_loops.h
>
15
#include <
analyses/local_may_alias.h
>
16
17
#include <
goto-programs/remove_skip.h
>
18
19
#include "
function_assigns.h
"
20
#include "
havoc_utils.h
"
21
#include "
loop_utils.h
"
22
23
class
havoc_loopst
24
{
25
public
:
26
typedef
goto_functionst::goto_functiont
goto_functiont
;
27
28
havoc_loopst
(
29
function_assignst
&_function_assigns,
30
goto_functiont
&_goto_function,
31
const
namespacet
&
ns
)
32
:
goto_function
(_goto_function),
33
local_may_alias
(_goto_function),
34
function_assigns
(_function_assigns),
35
natural_loops
(_goto_function.body),
36
ns
(
ns
)
37
{
38
havoc_loops
();
39
}
40
41
protected
:
42
goto_functiont
&
goto_function
;
43
local_may_aliast
local_may_alias
;
44
function_assignst
&
function_assigns
;
45
natural_loops_mutablet
natural_loops
;
46
const
namespacet
&
ns
;
47
48
typedef
std::set<exprt>
assignst
;
49
typedef
const
natural_loops_mutablet::natural_loopt
loopt
;
50
51
void
havoc_loops
();
52
53
void
havoc_loop
(
54
const
goto_programt::targett
loop_head,
55
const
loopt
&);
56
57
void
get_assigns
(
const
loopt
&,
assignst
&);
58
};
59
60
void
havoc_loopst::havoc_loop
(
61
const
goto_programt::targett
loop_head,
62
const
loopt
&loop)
63
{
64
PRECONDITION
(!loop.empty());
65
66
// first find out what can get changed in the loop
67
assignst
assigns;
68
get_assigns
(loop, assigns);
69
70
// build the havocking code
71
goto_programt
havoc_code;
72
havoc_utilst
havoc_gen(assigns,
ns
);
73
havoc_gen.
append_full_havoc_code
(loop_head->source_location(), havoc_code);
74
75
// Now havoc at the loop head. Use insert_swap to
76
// preserve jumps to loop head.
77
goto_function
.body.insert_before_swap(loop_head, havoc_code);
78
79
// compute the loop exit
80
goto_programt::targett
loop_exit=
81
get_loop_exit
(loop);
82
83
// divert all gotos to the loop head to the loop exit
84
for
(loopt::const_iterator
85
l_it=loop.begin(); l_it!=loop.end(); l_it++)
86
{
87
goto_programt::instructiont
&instruction=**l_it;
88
if
(instruction.
is_goto
())
89
{
90
for
(goto_programt::targetst::iterator
91
t_it=instruction.
targets
.begin();
92
t_it!=instruction.
targets
.end();
93
t_it++)
94
{
95
if
(*t_it==loop_head)
96
*t_it=loop_exit;
// divert
97
}
98
}
99
}
100
101
// remove skips
102
remove_skip
(
goto_function
.body);
103
}
104
105
void
havoc_loopst::get_assigns
(
const
loopt
&loop,
assignst
&assigns)
106
{
107
for
(
const
auto
&instruction_it : loop)
108
function_assigns
.get_assigns(
local_may_alias
, instruction_it, assigns);
109
}
110
111
void
havoc_loopst::havoc_loops
()
112
{
113
// iterate over the (natural) loops in the function
114
115
for
(
const
auto
&loop :
natural_loops
.loop_map)
116
havoc_loop
(loop.first, loop.second);
117
}
118
119
void
havoc_loops
(
goto_modelt
&goto_model)
120
{
121
function_assignst
function_assigns(goto_model.
goto_functions
);
122
123
for
(
auto
&gf_entry : goto_model.
goto_functions
.
function_map
)
124
{
125
havoc_loopst
(
126
function_assigns, gf_entry.second,
namespacet
{goto_model.symbol_table});
127
}
128
}
function_assignst
Definition
function_assigns.h:23
goto_functionst::function_map
function_mapt function_map
Definition
goto_functions.h:29
goto_functionst::goto_functiont
::goto_functiont goto_functiont
Definition
goto_functions.h:27
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::instructiont::is_goto
bool is_goto() const
Definition
goto_program.h:490
goto_programt::instructiont::targets
targetst targets
The list of successor instructions.
Definition
goto_program.h:413
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition
goto_program.h:72
goto_programt::targett
instructionst::iterator targett
Definition
goto_program.h:613
havoc_loopst
Definition
havoc_loops.cpp:24
havoc_loopst::havoc_loops
void havoc_loops()
Definition
havoc_loops.cpp:111
havoc_loopst::loopt
const natural_loops_mutablet::natural_loopt loopt
Definition
havoc_loops.cpp:49
havoc_loopst::havoc_loop
void havoc_loop(const goto_programt::targett loop_head, const loopt &)
Definition
havoc_loops.cpp:60
havoc_loopst::get_assigns
void get_assigns(const loopt &, assignst &)
Definition
havoc_loops.cpp:105
havoc_loopst::goto_function
goto_functiont & goto_function
Definition
havoc_loops.cpp:42
havoc_loopst::havoc_loopst
havoc_loopst(function_assignst &_function_assigns, goto_functiont &_goto_function, const namespacet &ns)
Definition
havoc_loops.cpp:28
havoc_loopst::local_may_alias
local_may_aliast local_may_alias
Definition
havoc_loops.cpp:43
havoc_loopst::goto_functiont
goto_functionst::goto_functiont goto_functiont
Definition
havoc_loops.cpp:26
havoc_loopst::function_assigns
function_assignst & function_assigns
Definition
havoc_loops.cpp:44
havoc_loopst::natural_loops
natural_loops_mutablet natural_loops
Definition
havoc_loops.cpp:45
havoc_loopst::assignst
std::set< exprt > assignst
Definition
havoc_loops.cpp:48
havoc_loopst::ns
const namespacet & ns
Definition
havoc_loops.cpp:46
havoc_utilst
Definition
havoc_utils.h:53
havoc_utilst::append_full_havoc_code
void append_full_havoc_code(const source_locationt location, goto_programt &dest)
Append goto instructions to havoc the full assigns set.
Definition
havoc_utils.cpp:21
local_may_aliast
Definition
local_may_alias.h:25
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition
namespace.h:91
natural_loops_templatet< goto_programt, goto_programt::targett, goto_programt::target_less_than >::natural_loopt
parentt::loopt natural_loopt
Definition
natural_loops.h:53
function_assigns.h
Compute objects assigned to in a function.
havoc_loops
void havoc_loops(goto_modelt &goto_model)
Definition
havoc_loops.cpp:119
havoc_loops.h
Havoc Loops.
havoc_utils.h
Utilities for building havoc code for expressions.
local_may_alias.h
Field-insensitive, location-sensitive may-alias analysis.
get_loop_exit
goto_programt::targett get_loop_exit(const loopt &loop)
Definition
loop_utils.cpp:21
loop_utils.h
Helper functions for k-induction and loop invariants.
natural_loops.h
Compute natural loops in a goto_function.
natural_loops_mutablet
natural_loops_templatet< goto_programt, goto_programt::targett, goto_programt::target_less_than > natural_loops_mutablet
Definition
natural_loops.h:95
remove_skip
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
Definition
remove_skip.cpp:87
remove_skip.h
Program Transformation.
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
goto-instrument
havoc_loops.cpp
Generated by
1.17.0