Skip to content

Commit cb18483

Browse files
Solver factory shouldn't have its own namespacet instance
The namespace is passed on into the solver allocated. If the solver factory goes out of scope then the solver will crash.
1 parent 73ebbb4 commit cb18483

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

src/cbmc/bmc.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ int bmct::do_language_agnostic_bmc(
276276
safety_checkert::resultt final_result = safety_checkert::resultt::SAFE;
277277
safety_checkert::resultt tmp_result = safety_checkert::resultt::SAFE;
278278
const symbol_tablet &symbol_table = model.get_symbol_table();
279+
namespacet ns(symbol_table);
279280
messaget message(ui);
280281
std::unique_ptr<path_storaget> worklist;
281282
std::string strategy = opts.get_option("exploration-strategy");
@@ -285,12 +286,10 @@ int bmct::do_language_agnostic_bmc(
285286
worklist = path_strategy_chooser.get(strategy);
286287
try
287288
{
289+
solver_factoryt solvers(
290+
opts, ns, ui, ui.get_ui() == ui_message_handlert::uit::XML_UI);
291+
288292
{
289-
solver_factoryt solvers(
290-
opts,
291-
symbol_table,
292-
ui,
293-
ui.get_ui() == ui_message_handlert::uit::XML_UI);
294293
std::unique_ptr<solver_factoryt::solvert> cbmc_solver =
295294
solvers.get_solver();
296295
prop_convt &pc = cbmc_solver->prop_conv();
@@ -333,11 +332,6 @@ int bmct::do_language_agnostic_bmc(
333332

334333
while(!worklist->empty())
335334
{
336-
solver_factoryt solvers(
337-
opts,
338-
symbol_table,
339-
ui,
340-
ui.get_ui() == ui_message_handlert::uit::XML_UI);
341335
std::unique_ptr<solver_factoryt::solvert> cbmc_solver =
342336
solvers.get_solver();
343337
prop_convt &pc = cbmc_solver->prop_conv();

src/goto-checker/solver_factory.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Author: Daniel Kroening, Peter Schrammel
1818
#include <util/message.h>
1919
#include <util/namespace.h>
2020
#include <util/options.h>
21-
#include <util/symbol_table.h>
2221
#include <util/version.h>
2322

2423
#ifdef _MSC_VER
@@ -35,12 +34,11 @@ Author: Daniel Kroening, Peter Schrammel
3534

3635
solver_factoryt::solver_factoryt(
3736
const optionst &_options,
38-
const symbol_tablet &_symbol_table,
37+
const namespacet &_ns,
3938
message_handlert &_message_handler,
4039
bool _output_xml_in_refinement)
4140
: options(_options),
42-
symbol_table(_symbol_table),
43-
ns(_symbol_table),
41+
ns(_ns),
4442
message_handler(_message_handler),
4543
output_xml_in_refinement(_output_xml_in_refinement)
4644
{

src/goto-checker/solver_factory.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ class namespacet;
2121
class optionst;
2222
class propt;
2323
class prop_convt;
24-
class symbol_tablet;
2524

2625
class solver_factoryt
2726
{
2827
public:
28+
/// Note: The solver returned will hold a reference to the namespace `ns`.
2929
solver_factoryt(
3030
const optionst &_options,
31-
const symbol_tablet &_symbol_table,
31+
const namespacet &_ns,
3232
message_handlert &_message_handler,
3333
bool _output_xml_in_refinement);
3434

@@ -62,8 +62,7 @@ class solver_factoryt
6262

6363
protected:
6464
const optionst &options;
65-
const symbol_tablet &symbol_table;
66-
namespacet ns;
65+
const namespacet &ns;
6766
message_handlert &message_handler;
6867
const bool output_xml_in_refinement;
6968

unit/path_strategies.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,10 @@ void _check_with_strategy(
377377
ret = cbmc_parse_optionst::get_goto_program(gm, opts, cmdline, log, mh);
378378
REQUIRE(ret == -1);
379379

380-
solver_factoryt initial_solvers(opts, gm.get_symbol_table(), mh, false);
380+
namespacet ns(gm.get_symbol_table());
381+
solver_factoryt solver_factory(opts, ns, mh, false);
381382
std::unique_ptr<solver_factoryt::solvert> cbmc_solver =
382-
initial_solvers.get_solver();
383+
solver_factory.get_solver();
383384
prop_convt &initial_pc = cbmc_solver->prop_conv();
384385
std::function<bool(void)> callback = []() { return false; };
385386

@@ -404,8 +405,7 @@ void _check_with_strategy(
404405

405406
while(!worklist->empty())
406407
{
407-
solver_factoryt solvers(opts, gm.get_symbol_table(), mh, false);
408-
cbmc_solver = solvers.get_solver();
408+
cbmc_solver = solver_factory.get_solver();
409409
prop_convt &pc = cbmc_solver->prop_conv();
410410
path_storaget::patht &resume = worklist->peek();
411411

0 commit comments

Comments
 (0)