CBMC
Loading...
Searching...
No Matches
havoc_loops.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Havoc Loops
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#include "havoc_loops.h"
13
16
18
19#include "function_assigns.h"
20#include "havoc_utils.h"
21#include "loop_utils.h"
22
59
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
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.
78
79 // compute the 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
103}
104
105void havoc_loopst::get_assigns(const loopt &loop, assignst &assigns)
106{
107 for(const auto &instruction_it : loop)
109}
110
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
119void 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 {
126 function_assigns, gf_entry.second, namespacet{goto_model.symbol_table});
127 }
128}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
void get_assigns(const local_may_aliast &local_may_alias, const goto_programt::const_targett, assignst &)
function_mapt function_map
::goto_functiont goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
goto_programt body
goto_functionst goto_functions
GOTO functions.
Definition goto_model.h:34
This class represents an instruction in the GOTO intermediate representation.
targetst targets
The list of successor instructions.
A generic container class for the GOTO intermediate representation of one function.
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
instructionst::iterator targett
const natural_loops_mutablet::natural_loopt loopt
void havoc_loop(const goto_programt::targett loop_head, const loopt &)
void get_assigns(const loopt &, assignst &)
goto_functiont & goto_function
havoc_loopst(function_assignst &_function_assigns, goto_functiont &_goto_function, const namespacet &ns)
local_may_aliast local_may_alias
goto_functionst::goto_functiont goto_functiont
function_assignst & function_assigns
natural_loops_mutablet natural_loops
std::set< exprt > assignst
const namespacet & ns
loop_mapt loop_map
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
Compute objects assigned to in a function.
void havoc_loops(goto_modelt &goto_model)
Havoc Loops.
Utilities for building havoc code for expressions.
Field-insensitive, location-sensitive may-alias analysis.
goto_programt::targett get_loop_exit(const loopt &loop)
Helper functions for k-induction and loop invariants.
Compute natural loops in a goto_function.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
Program Transformation.
#define PRECONDITION(CONDITION)
Definition invariant.h:463