Skip to content

Commit a2c47c4

Browse files
committed
Remove language_mode from goto_symext
`goto_symex_statet` holds a reference to a language mode, which was being initialised to `goto_symext::language_mode` in `goto_symext::initialize_entry_point_state`. That `goto_symext` object, however, may be the one created in `single_path_symex_only_checkert::initialize_worklist`, whereupon the `goto_symex_statet` will outlive it. Fix this problem by getting rid of the `language_mode` member of `goto_symext` and initialise `goto_symex_statet::language_mode` from a mode in the symbol table, which outlives all goto-symex objects.
1 parent e9bf6f8 commit a2c47c4

14 files changed

+26
-59
lines changed

src/goto-checker/symex_bmc.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Author: Daniel Kroening, [email protected]
1616

1717
#include <goto-programs/unwindset.h>
1818

19-
#include <linking/static_lifetime_init.h>
20-
2119
#include <limits>
2220

2321
symex_bmct::symex_bmct(
@@ -40,10 +38,6 @@ symex_bmct::symex_bmct(
4038
unwindset(unwindset),
4139
symex_coverage(ns)
4240
{
43-
const symbolt *init_symbol = outer_symbol_table.lookup(INITIALIZE_FUNCTION);
44-
if(init_symbol)
45-
language_mode = init_symbol->mode;
46-
4741
messaget msg{mh};
4842
msg.status() << "Starting Bounded Model Checking" << messaget::eom;
4943
}

src/goto-symex/goto_symex.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void goto_symext::do_simplify(exprt &expr, const statet &state)
3636
{
3737
if(state.threads.size() == 1)
3838
{
39-
simplify_expr_with_value_sett{state.value_set, language_mode, ns}
39+
simplify_expr_with_value_sett{state.value_set, state.language_mode, ns}
4040
.simplify(expr);
4141
}
4242
else
@@ -113,13 +113,7 @@ void goto_symext::symex_assign(
113113
assignment_type = symex_targett::assignment_typet::HIDDEN;
114114

115115
symex_assignt symex_assign{
116-
shadow_memory,
117-
state,
118-
assignment_type,
119-
ns,
120-
symex_config,
121-
language_mode,
122-
target};
116+
shadow_memory, state, assignment_type, ns, symex_config, target};
123117

124118
// Try to constant propagate potential side effects of the assignment, when
125119
// simplification is turned on and there is one thread only. Constant
@@ -149,13 +143,7 @@ void goto_symext::symex_assign(
149143

150144
exprt::operandst lhs_if_then_else_conditions;
151145
symex_assignt{
152-
shadow_memory,
153-
state,
154-
assignment_type,
155-
ns,
156-
symex_config,
157-
language_mode,
158-
target}
146+
shadow_memory, state, assignment_type, ns, symex_config, target}
159147
.assign_rec(lhs, expr_skeletont{}, rhs, lhs_if_then_else_conditions);
160148

161149
if(need_atomic_section)

src/goto-symex/goto_symex.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,6 @@ class goto_symext
235235
messaget::mstreamt &
236236
print_callstack_entry(const symex_targett::sourcet &target);
237237

238-
/// language_mode: ID_java, ID_C or another language identifier
239-
/// if we know the source language in use, irep_idt() otherwise.
240-
irep_idt language_mode;
241-
242238
/// The symbol table associated with the goto-program being executed.
243239
/// This symbol table will not have objects that are dynamically created as
244240
/// part of symbolic execution added to it; those object are stored in the

src/goto-symex/goto_symex_state.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,11 @@ class goto_symex_statet final : public goto_statet
258258
lvalue.id() == ID_array;
259259
}
260260

261-
private:
261+
/// language_mode: ID_java, ID_C or another language identifier
262+
/// if we know the source language in use, irep_idt() otherwise.
262263
const irep_idt &language_mode;
264+
265+
private:
263266
std::function<std::size_t(const irep_idt &)> fresh_l2_name_provider;
264267

265268
/// \brief Dangerous, do not use

src/goto-symex/symex_assign.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ void symex_assignt::assign_non_struct_symbol(
207207

208208
if(symex_config.simplify_opt)
209209
{
210-
simplify_expr_with_value_sett{state.value_set, language_mode, ns}.simplify(
211-
assignment.rhs);
210+
simplify_expr_with_value_sett{state.value_set, state.language_mode, ns}
211+
.simplify(assignment.rhs);
212212
}
213213

214214
const ssa_exprt l2_lhs = state

src/goto-symex/symex_assign.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ class symex_assignt
3333
symex_targett::assignment_typet assignment_type,
3434
const namespacet &ns,
3535
const symex_configt &symex_config,
36-
const irep_idt &language_mode,
3736
symex_targett &target)
3837
: shadow_memory(shadow_memory),
3938
state(state),
4039
assignment_type(assignment_type),
4140
ns(ns),
4241
symex_config(symex_config),
43-
language_mode(language_mode),
4442
target(target)
4543
{
4644
}
@@ -67,7 +65,6 @@ class symex_assignt
6765
symex_targett::assignment_typet assignment_type;
6866
const namespacet &ns;
6967
const symex_configt &symex_config;
70-
const irep_idt &language_mode;
7168
symex_targett &target;
7269

7370
void assign_from_struct(

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ void goto_symext::symex_allocate(
7272
{
7373
// to allow constant propagation
7474
exprt tmp_size = state.rename(size, ns).get();
75-
simplify_expr_with_value_sett{state.value_set, language_mode, ns}.simplify(
76-
tmp_size);
75+
simplify_expr_with_value_sett{state.value_set, state.language_mode, ns}
76+
.simplify(tmp_size);
7777

7878
// special treatment for sizeof(T)*x
7979
{
@@ -167,8 +167,8 @@ void goto_symext::symex_allocate(
167167

168168
// to allow constant propagation
169169
exprt zero_init = state.rename(to_binary_expr(code).op1(), ns).get();
170-
simplify_expr_with_value_sett{state.value_set, language_mode, ns}.simplify(
171-
zero_init);
170+
simplify_expr_with_value_sett{state.value_set, state.language_mode, ns}
171+
.simplify(zero_init);
172172

173173
INVARIANT(
174174
zero_init.is_constant(), "allocate expects constant as second argument");
@@ -433,7 +433,7 @@ void goto_symext::symex_printf(
433433
}
434434

435435
const irep_idt format_string =
436-
get_string_argument(operands[0], state.value_set, language_mode, ns);
436+
get_string_argument(operands[0], state.value_set, state.language_mode, ns);
437437

438438
if(!format_string.empty())
439439
target.output_fmt(
@@ -459,7 +459,7 @@ void goto_symext::symex_input(
459459
}
460460

461461
const irep_idt input_id =
462-
get_string_argument(id_arg, state.value_set, language_mode, ns);
462+
get_string_argument(id_arg, state.value_set, state.language_mode, ns);
463463

464464
target.input(state.guard.as_expr(), state.source, input_id, args);
465465
}
@@ -478,14 +478,15 @@ void goto_symext::symex_output(
478478
renamedt<exprt, L2> l2_arg = state.rename(code.operands()[i], ns);
479479
if(symex_config.simplify_opt)
480480
{
481-
simplify_expr_with_value_sett simp{state.value_set, language_mode, ns};
481+
simplify_expr_with_value_sett simp{
482+
state.value_set, state.language_mode, ns};
482483
l2_arg.simplify(simp);
483484
}
484485
args.emplace_back(l2_arg);
485486
}
486487

487488
const irep_idt output_id =
488-
get_string_argument(id_arg, state.value_set, language_mode, ns);
489+
get_string_argument(id_arg, state.value_set, state.language_mode, ns);
489490

490491
target.output(state.guard.as_expr(), state.source, output_id, args);
491492
}

src/goto-symex/symex_clean_expr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void goto_symext::process_array_expr(statet &state, exprt &expr)
127127
ns,
128128
state.symbol_table,
129129
symex_dereference_state,
130-
language_mode,
130+
state.language_mode,
131131
false,
132132
log.get_message_handler());
133133

@@ -187,7 +187,6 @@ void goto_symext::lift_let(statet &state, const let_exprt &let_expr)
187187
symex_targett::assignment_typet::HIDDEN,
188188
ns,
189189
symex_config,
190-
language_mode,
191190
target}
192191
.assign_symbol(
193192
to_ssa_expr(state.rename<L1>(let_expr.symbol(), ns).get()),

src/goto-symex/symex_dereference.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ goto_symext::cache_dereference(exprt &dereference_result, statet &state)
220220
"symex",
221221
"dereference_cache",
222222
dereference_result.source_location(),
223-
language_mode,
223+
state.language_mode,
224224
ns,
225225
state.symbol_table)
226226
.symbol_expr();
@@ -236,7 +236,6 @@ goto_symext::cache_dereference(exprt &dereference_result, statet &state)
236236
symex_targett::assignment_typet::STATE,
237237
ns,
238238
symex_config,
239-
language_mode,
240239
target};
241240

242241
assign.assign_symbol(
@@ -328,7 +327,7 @@ void goto_symext::dereference_rec(
328327
ns,
329328
state.symbol_table,
330329
symex_dereference_state,
331-
language_mode,
330+
state.language_mode,
332331
expr_is_not_null,
333332
log.get_message_handler());
334333

src/goto-symex/symex_function_call.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,7 @@ void goto_symext::parameter_assignments(
131131

132132
exprt::operandst lhs_conditions;
133133
symex_assignt{
134-
shadow_memory,
135-
state,
136-
assignment_type,
137-
ns,
138-
symex_config,
139-
language_mode,
140-
target}
134+
shadow_memory, state, assignment_type, ns, symex_config, target}
141135
.assign_rec(lhs, expr_skeletont{}, rhs, lhs_conditions);
142136
}
143137

0 commit comments

Comments
 (0)