Skip to content

Commit 8000a2f

Browse files
author
svorenova
authored
Merge pull request #2874 from svorenova/nondet_static_condition
Small fix and some cleaning in nondet-static [TG-2755]
2 parents a575f51 + 8230504 commit 8000a2f

File tree

3 files changed

+79
-32
lines changed

3 files changed

+79
-32
lines changed

jbmc/src/java_bytecode/java_bytecode_language.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ static symbol_exprt get_or_create_class_literal_symbol(
347347
new_class_symbol.is_lvalue = true;
348348
new_class_symbol.is_state_var = true;
349349
new_class_symbol.is_static_lifetime = true;
350+
new_class_symbol.type.set(ID_C_no_nondet_initialization, true);
350351
symbol_table.add(new_class_symbol);
351352
}
352353

src/goto-instrument/nondet_static.cpp

+65-29
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/*******************************************************************\
22
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).
57
68
Author: Daniel Kroening, Michael Tautschnig
79
@@ -10,14 +12,56 @@ Date: November 2011
1012
\*******************************************************************/
1113

1214
/// \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).
1419

1520
#include "nondet_static.h"
1621

1722
#include <goto-programs/goto_model.h>
1823

1924
#include <linking/static_lifetime_init.h>
2025

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.
2165
void nondet_static(
2266
const namespacet &ns,
2367
goto_functionst &goto_functions,
@@ -38,34 +82,17 @@ void nondet_static(
3882
const symbol_exprt &sym=to_symbol_expr(
3983
to_code_assign(instruction.code).lhs());
4084

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))
4986
{
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;
5195
}
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;
6996
}
7097
else if(instruction.is_function_call())
7198
{
@@ -78,6 +105,10 @@ void nondet_static(
78105
}
79106
}
80107

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.
81112
void nondet_static(
82113
const namespacet &ns,
83114
goto_functionst &goto_functions)
@@ -88,6 +119,11 @@ void nondet_static(
88119
goto_functions.update();
89120
}
90121

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.
91127
void nondet_static(goto_modelt &goto_model)
92128
{
93129
const namespacet ns(goto_model.symbol_table);

src/goto-instrument/nondet_static.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/*******************************************************************\
22
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).
57
68
Author: Daniel Kroening, Michael Tautschnig
79
@@ -10,14 +12,22 @@ Date: November 2011
1012
\*******************************************************************/
1113

1214
/// \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).
1419

1520
#ifndef CPROVER_GOTO_INSTRUMENT_NONDET_STATIC_H
1621
#define CPROVER_GOTO_INSTRUMENT_NONDET_STATIC_H
1722

1823
class goto_modelt;
1924
class namespacet;
2025
class goto_functionst;
26+
class symbol_exprt;
27+
28+
bool is_nondet_initializable_static(
29+
const symbol_exprt &sym,
30+
const namespacet &ns);
2131

2232
void nondet_static(
2333
const namespacet &ns,

0 commit comments

Comments
 (0)