Skip to content

Commit cbb5fba

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 636d0b3 commit cbb5fba

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

src/goto-instrument/nondet_static.cpp

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

1919
#include <linking/static_lifetime_init.h>
2020

21+
/// See the return.
22+
/// \param sym The symbol expression to analyze.
23+
/// \param ns Namespace for resolving type information
24+
/// \return True if the symbol expression holds a static symbol which can be
25+
/// nondeterministically initialized, false otherwise.
26+
bool is_nondet_initializable_static(
27+
const symbol_exprt &sym,
28+
const namespacet &ns)
29+
{
30+
const irep_idt &id = sym.get_identifier();
31+
32+
// is it a __CPROVER_* variable?
33+
if(has_prefix(id2string(id), CPROVER_PREFIX))
34+
return false;
35+
36+
// variable not in symbol table such as symex variable?
37+
if(!ns.get_symbol_table().has_symbol(id))
38+
return false;
39+
40+
// is the type explicitly marked as not to be nondet initialized?
41+
if(ns.lookup(id).type.get_bool(ID_C_no_nondet_initialization))
42+
return false;
43+
44+
// static lifetime?
45+
if(!ns.lookup(id).is_static_lifetime)
46+
return false;
47+
48+
// constant?
49+
return !is_constant_or_has_constant_components(sym.type(), ns) &&
50+
!is_constant_or_has_constant_components(ns.lookup(id).type, ns);
51+
}
52+
53+
2154
void nondet_static(
2255
const namespacet &ns,
2356
goto_functionst &goto_functions,
@@ -38,34 +71,17 @@ void nondet_static(
3871
const symbol_exprt &sym=to_symbol_expr(
3972
to_code_assign(instruction.code).lhs());
4073

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))
74+
if(is_nondet_initializable_static(sym, ns))
4975
{
50-
continue;
76+
const goto_programt::instructiont original_instruction = instruction;
77+
i_it->make_assignment();
78+
i_it->code = code_assignt(
79+
sym,
80+
side_effect_expr_nondett(
81+
sym.type(), original_instruction.source_location));
82+
i_it->source_location = original_instruction.source_location;
83+
i_it->function = original_instruction.function;
5184
}
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;
6985
}
7086
else if(instruction.is_function_call())
7187
{

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)