@@ -18,6 +18,39 @@ Date: November 2011
18
18
19
19
#include < linking/static_lifetime_init.h>
20
20
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
+
21
54
void nondet_static (
22
55
const namespacet &ns,
23
56
goto_functionst &goto_functions,
@@ -38,34 +71,17 @@ void nondet_static(
38
71
const symbol_exprt &sym=to_symbol_expr (
39
72
to_code_assign (instruction.code ).lhs ());
40
73
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))
49
75
{
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 ;
51
84
}
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 ;
69
85
}
70
86
else if (instruction.is_function_call ())
71
87
{
0 commit comments