Skip to content

Commit 0c6d6b2

Browse files
authored
Merge pull request #3961 from tautschnig/fix-3956-namespace
Restore namespace after symbolic execution [blocks: #3976]
2 parents c59500b + 23196af commit 0c6d6b2

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--symex-coverage-report - --paths lifo
4+
<line branch="false" hits="1" number="12"/>
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
^warning: ignoring

src/goto-symex/symex_main.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,34 @@ void goto_symext::symex_with_state(
254254
const get_goto_functiont &get_goto_function,
255255
symbol_tablet &new_symbol_table)
256256
{
257+
// resets the namespace to only wrap a single symbol table, and does so upon
258+
// destruction of an object of this type; instantiating the type is thus all
259+
// that's needed to achieve a reset upon exiting this method
260+
struct reset_namespacet
261+
{
262+
explicit reset_namespacet(namespacet &ns) : ns(ns)
263+
{
264+
}
265+
266+
~reset_namespacet()
267+
{
268+
const symbol_tablet &st = ns.get_symbol_table();
269+
ns = namespacet(st);
270+
}
271+
272+
namespacet &ns;
273+
};
274+
257275
// We'll be using ns during symbolic execution and it needs to know
258276
// about the names minted in `state`, so make it point both to
259277
// `state`'s symbol table and the symbol table of the original
260278
// goto-program.
261279
ns = namespacet(outer_symbol_table, state.symbol_table);
262280

281+
// whichever way we exit this method, reset the namespace back to a sane state
282+
// as state.symbol_table might go out of scope
283+
reset_namespacet reset_ns(ns);
284+
263285
PRECONDITION(state.top().end_of_function->is_end_function());
264286

265287
symex_threaded_step(state, get_goto_function);
@@ -279,9 +301,6 @@ void goto_symext::symex_with_state(
279301
// execution, so return the names generated through symbolic execution
280302
// through `new_symbol_table`.
281303
new_symbol_table = state.symbol_table;
282-
// reset the namespace back to a sane state as state.symbol_table might go out
283-
// of scope
284-
ns = namespacet(outer_symbol_table);
285304
}
286305

287306
void goto_symext::resume_symex_from_saved_state(

0 commit comments

Comments
 (0)