1
1
/* ******************************************************************\
2
2
3
- Module: Nondeterministic initialization of certain global scope
4
- variables
3
+ Module: Nondeterministically initializes global scope variables, except for
4
+ constants (such as string literals, final fields) and internal variables
5
+ (such as CPROVER and symex variables, language specific internal
6
+ variables).
5
7
6
8
Author: Daniel Kroening, Michael Tautschnig
7
9
@@ -10,14 +12,56 @@ Date: November 2011
10
12
\*******************************************************************/
11
13
12
14
// / \file
13
- // / Nondeterministic initialization of certain global scope variables
15
+ // / Nondeterministically initializes global scope variables, except for
16
+ // / constants (such as string literals, final fields) and internal variables
17
+ // / (such as CPROVER and symex variables, language specific internal
18
+ // / variables).
14
19
15
20
#include " nondet_static.h"
16
21
17
22
#include < goto-programs/goto_model.h>
18
23
19
24
#include < linking/static_lifetime_init.h>
20
25
26
+ // / See the return.
27
+ // / \param sym The symbol expression to analyze.
28
+ // / \param ns Namespace for resolving type information
29
+ // / \return True if the symbol expression holds a static symbol which can be
30
+ // / nondeterministically initialized, false otherwise.
31
+ bool is_nondet_initializable_static (
32
+ const symbol_exprt &sym,
33
+ const namespacet &ns)
34
+ {
35
+ const irep_idt &id = sym.get_identifier ();
36
+
37
+ // is it a __CPROVER_* variable?
38
+ if (has_prefix (id2string (id), CPROVER_PREFIX))
39
+ return false ;
40
+
41
+ // variable not in symbol table such as symex variable?
42
+ if (!ns.get_symbol_table ().has_symbol (id))
43
+ return false ;
44
+
45
+ // is the type explicitly marked as not to be nondet initialized?
46
+ if (ns.lookup (id).type .get_bool (ID_C_no_nondet_initialization))
47
+ return false ;
48
+
49
+ // static lifetime?
50
+ if (!ns.lookup (id).is_static_lifetime )
51
+ return false ;
52
+
53
+ // constant?
54
+ return !is_constant_or_has_constant_components (sym.type (), ns) &&
55
+ !is_constant_or_has_constant_components (ns.lookup (id).type , ns);
56
+ }
57
+
58
+ // / Nondeterministically initializes global scope variables in a goto-function.
59
+ // / Iterates over instructions in the specified function and replaces all values
60
+ // / assigned to nondet-initializable static variables with nondeterministic
61
+ // / values.
62
+ // / \param ns Namespace for resolving type information.
63
+ // / \param [out] goto_functions Existing goto-functions to be updated.
64
+ // / \param fct_name Name of the goto-function to be updated.
21
65
void nondet_static (
22
66
const namespacet &ns,
23
67
goto_functionst &goto_functions,
@@ -38,34 +82,17 @@ void nondet_static(
38
82
const symbol_exprt &sym=to_symbol_expr (
39
83
to_code_assign (instruction.code ).lhs ());
40
84
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))
85
+ if (is_nondet_initializable_static (sym, ns))
49
86
{
50
- continue ;
87
+ const goto_programt::instructiont original_instruction = instruction;
88
+ i_it->make_assignment ();
89
+ i_it->code = code_assignt (
90
+ sym,
91
+ side_effect_expr_nondett (
92
+ sym.type (), original_instruction.source_location ));
93
+ i_it->source_location = original_instruction.source_location ;
94
+ i_it->function = original_instruction.function ;
51
95
}
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
96
}
70
97
else if (instruction.is_function_call ())
71
98
{
@@ -78,6 +105,10 @@ void nondet_static(
78
105
}
79
106
}
80
107
108
+ // / Nondeterministically initializes global scope variables in
109
+ // / CPROVER_initialize function.
110
+ // / \param ns Namespace for resolving type information.
111
+ // / \param [out] goto_functions Existing goto-functions to be updated.
81
112
void nondet_static (
82
113
const namespacet &ns,
83
114
goto_functionst &goto_functions)
@@ -88,6 +119,11 @@ void nondet_static(
88
119
goto_functions.update ();
89
120
}
90
121
122
+ // / Main entry point of the module. Nondeterministically initializes global
123
+ // / scope variables, except for constants (such as string literals, final
124
+ // / fields) and internal variables (such as CPROVER and symex variables,
125
+ // / language specific internal variables).
126
+ // / \param [out] goto_model Existing goto-model to be updated.
91
127
void nondet_static (goto_modelt &goto_model)
92
128
{
93
129
const namespacet ns (goto_model.symbol_table );
0 commit comments