Skip to content

Commit 1bc6d87

Browse files
Daniel Kroeningtautschnig
Daniel Kroening
authored andcommitted
Ensure goto_symex_statet::source is always set
sourcet contains an interator, and the interface explicitly allows it to be uninitialised. However, most parts of the code base access source.pc without checking.
1 parent 3fe7c67 commit 1bc6d87

File tree

7 files changed

+26
-31
lines changed

7 files changed

+26
-31
lines changed

src/goto-instrument/accelerate/scratch_program.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ bool scratch_programt::check_sat(bool do_slice)
3535
output(ns, "scratch", std::cout);
3636
#endif
3737

38-
symex.symex_with_state(symex_state, functions, symex_symbol_table);
38+
symex_state = util_make_unique<goto_symex_statet>(
39+
symex_targett::sourcet(goto_functionst::entry_point(), *this));
40+
symex.symex_with_state(*symex_state, functions, symex_symbol_table);
3941

4042
if(do_slice)
4143
{
@@ -64,7 +66,7 @@ exprt scratch_programt::eval(const exprt &e)
6466
{
6567
exprt ssa=e;
6668

67-
symex_state.rename(ssa, ns);
69+
symex_state->rename(ssa, ns);
6870

6971
return checker->get(ssa);
7072
}

src/goto-instrument/accelerate/scratch_program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class scratch_programt:public goto_programt
7474
bool constant_propagation;
7575

7676
protected:
77-
goto_symex_statet symex_state;
77+
std::unique_ptr<goto_symex_statet> symex_state;
7878
goto_functionst functions;
7979
symbol_tablet &symbol_table;
8080
symbol_tablet symex_symbol_table;

src/goto-symex/goto_symex_state.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Author: Daniel Kroening, [email protected]
2727

2828
static void get_l1_name(exprt &expr);
2929

30-
goto_symex_statet::goto_symex_statet()
31-
: symex_target(nullptr), record_events(true), dirty()
30+
goto_symex_statet::goto_symex_statet(const symex_targett::sourcet &_source)
31+
: goto_statet(_source), symex_target(nullptr), record_events(true), dirty()
3232
{
3333
threads.resize(1);
3434
new_frame();
@@ -724,11 +724,8 @@ void goto_symex_statet::print_backtrace(std::ostream &out) const
724724
++stackit)
725725
{
726726
const auto &frame = *stackit;
727-
if(frame.calling_location.is_set)
728-
{
729-
out << frame.calling_location.function_id << " "
730-
<< frame.calling_location.pc->location_number << "\n";
731-
}
727+
out << frame.calling_location.function_id << " "
728+
<< frame.calling_location.pc->location_number << "\n";
732729
}
733730
}
734731

src/goto-symex/goto_symex_state.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ class goto_statet
7272
unsigned total_vccs = 0;
7373
unsigned remaining_vccs = 0;
7474

75+
/// Constructors
7576
explicit goto_statet(const class goto_symex_statet &s);
76-
goto_statet() = default;
77+
explicit goto_statet(const symex_targett::sourcet &_source) : source(_source)
78+
{
79+
}
7780
};
7881

7982
// stack frames -- these are used for function calls and
@@ -124,7 +127,7 @@ struct framet
124127
class goto_symex_statet final : public goto_statet
125128
{
126129
public:
127-
goto_symex_statet();
130+
explicit goto_symex_statet(const symex_targett::sourcet &);
128131
~goto_symex_statet();
129132

130133
/// \brief Fake "copy constructor" that initializes the `symex_target` member
@@ -141,7 +144,6 @@ class goto_symex_statet final : public goto_statet
141144
/// for error traces even after symbolic execution has finished.
142145
symbol_tablet symbol_table;
143146

144-
symex_targett::sourcet source;
145147
symex_target_equationt *symex_target;
146148

147149
// we remember all L1 renamings

src/goto-symex/symex_function_call.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ void goto_symext::symex_function_call_code(
321321
frame.loop_iterations[identifier].is_recursion=true;
322322
frame.loop_iterations[identifier].count++;
323323

324-
state.source.is_set=true;
325324
state.source.function_id = identifier;
326325
symex_transition(state, goto_function.body.instructions.begin(), false);
327326
}

src/goto-symex/symex_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ void goto_symext::symex_from_entry_point_of(
339339
throw unsupported_operation_exceptiont("the program has no entry point");
340340
}
341341

342-
statet state;
342+
statet state(symex_targett::sourcet(
343+
goto_functionst::entry_point(), start_function->body));
343344

344345
state.run_validation_checks = symex_config.run_validation_checks;
345346

src/goto-symex/symex_target_equation.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -697,15 +697,12 @@ void symex_target_equationt::SSA_stept::output(
697697
const namespacet &ns,
698698
std::ostream &out) const
699699
{
700-
if(source.is_set)
701-
{
702-
out << "Thread " << source.thread_nr;
700+
out << "Thread " << source.thread_nr;
703701

704-
if(source.pc->source_location.is_not_nil())
705-
out << " " << source.pc->source_location << '\n';
706-
else
707-
out << '\n';
708-
}
702+
if(source.pc->source_location.is_not_nil())
703+
out << " " << source.pc->source_location << '\n';
704+
else
705+
out << '\n';
709706

710707
switch(type)
711708
{
@@ -798,15 +795,12 @@ void symex_target_equationt::SSA_stept::output(
798795

799796
void symex_target_equationt::SSA_stept::output(std::ostream &out) const
800797
{
801-
if(source.is_set)
802-
{
803-
out << "Thread " << source.thread_nr;
798+
out << "Thread " << source.thread_nr;
804799

805-
if(source.pc->source_location.is_not_nil())
806-
out << " " << source.pc->source_location << '\n';
807-
else
808-
out << '\n';
809-
}
800+
if(source.pc->source_location.is_not_nil())
801+
out << " " << source.pc->source_location << '\n';
802+
else
803+
out << '\n';
810804

811805
switch(type)
812806
{

0 commit comments

Comments
 (0)