Skip to content

Commit 43f4902

Browse files
author
svorenova
committed
Pull out a function to check conditions for nondet-static
So that the function can be called from other files too
1 parent 395b8b9 commit 43f4902

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

src/goto-instrument/nondet_static.cpp

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,38 @@ Date: November 2011
1818

1919
#include <linking/static_lifetime_init.h>
2020

21+
/// Returns true if the symbol expression holds a static symbol that can be
22+
/// nondeterministically initialized, false otherwise.
23+
/// \param sym The symbol expression to analyze.
24+
/// \param ns Namespace for resolving type information
25+
bool is_nondet_initializable_static(
26+
const symbol_exprt &sym,
27+
const namespacet &ns)
28+
{
29+
const irep_idt &id = sym.get_identifier();
30+
31+
// is it a __CPROVER_* variable?
32+
if(has_prefix(id2string(id), CPROVER_PREFIX))
33+
return false;
34+
35+
// variable not in symbol table such as symex variable?
36+
if(!ns.get_symbol_table().has_symbol(id))
37+
return false;
38+
39+
// any other internal variable such as Java specific?
40+
if(ns.lookup(id).type.get_bool(ID_C_no_nondet_initialization))
41+
return false;
42+
43+
// static lifetime?
44+
if(!ns.lookup(id).is_static_lifetime)
45+
return false;
46+
47+
// constant?
48+
return !is_constant_or_has_constant_components(sym.type(), ns) &&
49+
!is_constant_or_has_constant_components(ns.lookup(id).type, ns);
50+
}
51+
52+
2153
void nondet_static(
2254
const namespacet &ns,
2355
goto_functionst &goto_functions,
@@ -38,34 +70,17 @@ void nondet_static(
3870
const symbol_exprt &sym=to_symbol_expr(
3971
to_code_assign(instruction.code).lhs());
4072

41-
// is it a __CPROVER_* variable?
42-
if(has_prefix(id2string(sym.get_identifier()), CPROVER_PREFIX))
43-
continue;
44-
45-
// any other internal variable such as Java specific?
46-
if(
47-
ns.lookup(sym.get_identifier())
48-
.type.get_bool(ID_C_no_nondet_initialization))
73+
if(is_nondet_initializable_static(sym, ns))
4974
{
50-
continue;
75+
const goto_programt::instructiont original_instruction = instruction;
76+
i_it->make_assignment();
77+
i_it->code = code_assignt(
78+
sym,
79+
side_effect_expr_nondett(
80+
sym.type(), original_instruction.source_location));
81+
i_it->source_location = original_instruction.source_location;
82+
i_it->function = original_instruction.function;
5183
}
52-
53-
// static lifetime?
54-
if(!ns.lookup(sym.get_identifier()).is_static_lifetime)
55-
continue;
56-
57-
// constant?
58-
if(is_constant_or_has_constant_components(sym.type(), ns))
59-
continue;
60-
61-
const goto_programt::instructiont original_instruction = instruction;
62-
i_it->make_assignment();
63-
i_it->code = code_assignt(
64-
sym,
65-
side_effect_expr_nondett(
66-
sym.type(), original_instruction.source_location));
67-
i_it->source_location = original_instruction.source_location;
68-
i_it->function = original_instruction.function;
6984
}
7085
else if(instruction.is_function_call())
7186
{

src/goto-instrument/nondet_static.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Date: November 2011
1818
class goto_modelt;
1919
class namespacet;
2020
class goto_functionst;
21+
class symbol_exprt;
22+
23+
bool is_nondet_initializable_static(
24+
const symbol_exprt &sym,
25+
const namespacet &ns);
2126

2227
void nondet_static(
2328
const namespacet &ns,

0 commit comments

Comments
 (0)