cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
symex_atomic_section.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Symbolic Execution
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
11
12
#include "
goto_symex.h
"
13
14
#include <
util/exception_utils.h
>
15
16
void
goto_symext::symex_atomic_begin
(
statet
&state)
17
{
18
if
(!state.
reachable
)
19
return
;
20
21
if
(state.
atomic_section_id
!= 0)
22
throw
incorrect_goto_program_exceptiont
(
23
"we don't support nesting of atomic sections"
,
24
state.
source
.
pc
->source_location());
25
26
state.
atomic_section_id
=++
atomic_section_counter
;
27
state.
read_in_atomic_section
.clear();
28
state.
written_in_atomic_section
.clear();
29
30
target
.atomic_begin(
31
state.
guard
.
as_expr
(),
32
atomic_section_counter
,
33
state.
source
);
34
}
35
36
void
goto_symext::symex_atomic_end
(
statet
&state)
37
{
38
if
(!state.
reachable
)
39
return
;
40
41
if
(state.
atomic_section_id
== 0)
42
throw
incorrect_goto_program_exceptiont
(
43
"ATOMIC_END unmatched"
, state.
source
.
pc
->source_location());
44
45
const
unsigned
atomic_section_id=state.
atomic_section_id
;
46
state.
atomic_section_id
=0;
47
48
for
(
const
auto
&pair : state.
read_in_atomic_section
)
49
{
50
ssa_exprt
r
= pair.first;
51
r
.set_level_2(pair.second.first);
52
53
// guard is the disjunction over reads
54
PRECONDITION
(!pair.second.second.empty());
55
guardt
read_guard(pair.second.second.front());
56
for
(std::list<guardt>::const_iterator it = ++(pair.second.second.begin());
57
it != pair.second.second.end();
58
++it)
59
read_guard|=*it;
60
exprt
read_guard_expr=read_guard.
as_expr
();
61
do_simplify
(read_guard_expr, state.
value_set
);
62
63
target
.shared_read(
64
read_guard_expr,
65
r
,
66
atomic_section_id,
67
state.
source
);
68
}
69
70
for
(
const
auto
&pair : state.
written_in_atomic_section
)
71
{
72
ssa_exprt
w = pair.first;
73
w.
set_level_2
(state.
get_level2
().
latest_index
(w.
get_identifier
()));
74
75
// guard is the disjunction over writes
76
PRECONDITION
(!pair.second.empty());
77
guardt
write_guard(pair.second.front());
78
for
(std::list<guardt>::const_iterator it = ++(pair.second.begin());
79
it != pair.second.end();
80
++it)
81
write_guard|=*it;
82
exprt
write_guard_expr=write_guard.
as_expr
();
83
do_simplify
(write_guard_expr, state.
value_set
);
84
85
target
.shared_write(
86
write_guard_expr,
87
w,
88
atomic_section_id,
89
state.
source
);
90
}
91
92
target
.atomic_end(
93
state.
guard
.
as_expr
(),
94
atomic_section_id,
95
state.
source
);
96
}
exprt
Base class for all expressions.
Definition
expr.h:57
goto_statet::guard
guardt guard
Definition
goto_state.h:58
goto_statet::reachable
bool reachable
Is this code reachable?
Definition
goto_state.h:62
goto_statet::atomic_section_id
unsigned atomic_section_id
Threads.
Definition
goto_state.h:76
goto_statet::value_set
value_sett value_set
Uses level 1 names, and is used to do dereferencing.
Definition
goto_state.h:51
goto_statet::get_level2
const symex_level2t & get_level2() const
Definition
goto_state.h:45
goto_symex_statet::read_in_atomic_section
std::unordered_map< ssa_exprt, a_s_r_entryt, irep_hash > read_in_atomic_section
Definition
goto_symex_state.h:181
goto_symex_statet::written_in_atomic_section
std::unordered_map< ssa_exprt, a_s_w_entryt, irep_hash > written_in_atomic_section
Definition
goto_symex_state.h:183
goto_symex_statet::source
symex_targett::sourcet source
Definition
goto_symex_state.h:62
goto_symext::statet
goto_symex_statet statet
A type abbreviation for goto_symex_statet.
Definition
goto_symex.h:41
goto_symext::symex_atomic_begin
virtual void symex_atomic_begin(statet &state)
Symbolically execute an ATOMIC_BEGIN instruction.
Definition
symex_atomic_section.cpp:16
goto_symext::target
symex_target_equationt & target
The equation that this execution is building up.
Definition
goto_symex.h:264
goto_symext::atomic_section_counter
unsigned atomic_section_counter
A monotonically increasing index for each encountered ATOMIC_BEGIN instruction.
Definition
goto_symex.h:268
goto_symext::do_simplify
virtual void do_simplify(exprt &expr, const value_sett &value_set)
Definition
goto_symex.cpp:32
goto_symext::symex_atomic_end
virtual void symex_atomic_end(statet &state)
Symbolically execute an ATOMIC_END instruction.
Definition
symex_atomic_section.cpp:36
guard_exprt::as_expr
exprt as_expr() const
Definition
guard_expr.h:46
incorrect_goto_program_exceptiont
Thrown when a goto program that's being processed is in an invalid format, for example passing the wr...
Definition
exception_utils.h:92
ssa_exprt
Expression providing an SSA-renamed symbol of expressions.
Definition
ssa_expr.h:17
ssa_exprt::set_level_2
void set_level_2(std::size_t i)
Definition
ssa_expr.cpp:193
symbol_exprt::get_identifier
const irep_idt & get_identifier() const
Definition
std_expr.h:161
exception_utils.h
goto_symex.h
Symbolic Execution.
guardt
guard_exprt guardt
Definition
guard.h:29
r
static int8_t r
Definition
irep_hash.h:60
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
symex_level2t::latest_index
unsigned latest_index(const irep_idt &identifier) const
Counter corresponding to an identifier.
Definition
renaming_level.cpp:131
symex_targett::sourcet::pc
goto_programt::const_targett pc
Definition
symex_target.h:42
goto-symex
symex_atomic_section.cpp
Generated by
1.17.0