Skip to content

Commit 12afabb

Browse files
author
Daniel Kroening
committed
symex_targett::sourcet now knows the function identifier
1 parent d1733d8 commit 12afabb

10 files changed

+50
-34
lines changed

src/cbmc/symex_bmc.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ void symex_bmct::symex_step(
6565

6666
goto_symext::symex_step(get_goto_function, state);
6767

68-
if(record_coverage &&
69-
// avoid an invalid iterator in state.source.pc
70-
(!cur_pc->is_end_function() ||
71-
cur_pc->function!=goto_functionst::entry_point()))
68+
if(
69+
record_coverage &&
70+
// avoid an invalid iterator in state.source.pc
71+
(!cur_pc->is_end_function() ||
72+
state.source.function != goto_functionst::entry_point()))
7273
{
7374
// forward goto will effectively be covered via phi function,
7475
// which does not invoke symex_step; as symex_step is called

src/goto-symex/build_goto_trace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void update_internal_field(
156156
}
157157

158158
// set internal field to _start function-return step
159-
if(SSA_step.source.pc->function==goto_functionst::entry_point())
159+
if(SSA_step.source.function == goto_functionst::entry_point())
160160
{
161161
// "__CPROVER_*" function calls in __CPROVER_start are already marked as
162162
// internal. Don't mark any other function calls (i.e. "main"), function

src/goto-symex/goto_symex.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ class goto_symext
148148
/// procedure.
149149
/// \param state Symex state to start with.
150150
/// \param goto_functions GOTO model to symex.
151+
/// \param function_identifier The function with the instruction range
151152
/// \param first Entry point in form of a first instruction.
152153
/// \param limit Final instruction, which itself will not be symexed.
153154
virtual void symex_instruction_range(
154155
statet &,
155156
const goto_functionst &,
157+
const irep_idt &function_identifier,
156158
goto_programt::const_targett first,
157159
goto_programt::const_targett limit);
158160

@@ -162,11 +164,13 @@ class goto_symext
162164
/// procedure.
163165
/// \param state Symex state to start with.
164166
/// \param get_goto_function retrieves a function body
167+
/// \param function_identifier The function with the instruction range
165168
/// \param first Entry point in form of a first instruction.
166169
/// \param limit Final instruction, which itself will not be symexed.
167170
virtual void symex_instruction_range(
168171
statet &state,
169172
const get_goto_functiont &get_goto_function,
173+
const irep_idt &function_identifier,
170174
goto_programt::const_targett first,
171175
goto_programt::const_targett limit);
172176

@@ -183,13 +187,15 @@ class goto_symext
183187
/// Initialise the symbolic execution and the given state with <code>pc</code>
184188
/// as entry point.
185189
/// \param state Symex state to initialise.
186-
/// \param goto_functions GOTO model to symex.
190+
/// \param get_goto_function producer for GOTO functions
191+
/// \param function_identifier The function in which the instructions are
187192
/// \param pc first instruction to symex
188193
/// \param limit final instruction, which itself will not
189194
/// be symexed.
190195
void initialize_entry_point(
191196
statet &state,
192197
const get_goto_functiont &get_goto_function,
198+
const irep_idt &function_identifier,
193199
goto_programt::const_targett pc,
194200
goto_programt::const_targett limit);
195201

src/goto-symex/show_program.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void show_program(const namespacet &ns, const symex_target_equationt &equation)
2929
{
3030
std::cout << "// " << step.source.pc->location_number << " ";
3131
std::cout << step.source.pc->source_location.as_string() << "\n";
32-
const irep_idt &function = step.source.pc->function;
32+
const irep_idt &function = step.source.function;
3333

3434
if(step.is_assignment())
3535
{

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ void goto_symext::symex_allocate(
5555

5656
exprt size=code.op0();
5757
typet object_type=nil_typet();
58-
auto function_symbol = outer_symbol_table.lookup(state.source.pc->function);
59-
INVARIANT(function_symbol, "function associated with instruction not found");
58+
auto function_symbol = outer_symbol_table.lookup(state.source.function);
59+
INVARIANT(function_symbol, "function associated with allocation not found");
6060
const irep_idt &mode = function_symbol->mode;
6161

6262
// is the type given?

src/goto-symex/symex_dereference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void goto_symext::dereference_rec(
258258

259259
if(state.threads.size() == 1)
260260
{
261-
const irep_idt &expr_function = state.source.pc->function;
261+
const irep_idt &expr_function = state.source.function;
262262
if(!expr_function.empty())
263263
{
264264
state.get_original_name(to_check);

src/goto-symex/symex_function_call.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ void goto_symext::symex_function_call_code(
310310
frame.loop_iterations[identifier].count++;
311311

312312
state.source.is_set=true;
313+
state.source.function = identifier;
313314
symex_transition(state, goto_function.body.instructions.begin());
314315
}
315316

@@ -358,7 +359,7 @@ void goto_symext::symex_end_of_function(statet &state)
358359
{
359360
// first record the return
360361
target.function_return(
361-
state.guard.as_expr(), state.source.pc->function, state.source);
362+
state.guard.as_expr(), state.source.function, state.source);
362363

363364
// then get rid of the frame
364365
pop_frame(state);

src/goto-symex/symex_main.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,13 @@ void goto_symext::rewrite_quantifiers(exprt &expr, statet &state)
121121
void goto_symext::initialize_entry_point(
122122
statet &state,
123123
const get_goto_functiont &get_goto_function,
124+
const irep_idt &function_identifier,
124125
const goto_programt::const_targett pc,
125126
const goto_programt::const_targett limit)
126127
{
127128
PRECONDITION(!state.threads.empty());
128129
PRECONDITION(!state.call_stack().empty());
129-
state.source=symex_targett::sourcet(pc);
130+
state.source = symex_targett::sourcet(function_identifier, pc);
130131
state.top().end_of_function=limit;
131132
state.top().calling_location.pc=state.top().end_of_function;
132133
state.symex_target=&target;
@@ -250,22 +251,29 @@ void goto_symext::resume_symex_from_saved_state(
250251
void goto_symext::symex_instruction_range(
251252
statet &state,
252253
const goto_functionst &goto_functions,
254+
const irep_idt &function_identifier,
253255
const goto_programt::const_targett first,
254256
const goto_programt::const_targett limit)
255257
{
256258
symex_instruction_range(
257-
state, get_function_from_goto_functions(goto_functions), first, limit);
259+
state,
260+
get_function_from_goto_functions(goto_functions),
261+
function_identifier,
262+
first,
263+
limit);
258264
}
259265

260266
void goto_symext::symex_instruction_range(
261267
statet &state,
262268
const get_goto_functiont &get_goto_function,
269+
const irep_idt &function_identifier,
263270
const goto_programt::const_targett first,
264271
const goto_programt::const_targett limit)
265272
{
266-
initialize_entry_point(state, get_goto_function, first, limit);
273+
initialize_entry_point(
274+
state, get_goto_function, function_identifier, first, limit);
267275
ns = namespacet(outer_symbol_table, state.symbol_table);
268-
while(state.source.pc->function!=limit->function || state.source.pc!=limit)
276+
while(state.source.function != limit->function || state.source.pc != limit)
269277
symex_threaded_step(state, get_goto_function);
270278
}
271279

@@ -296,6 +304,7 @@ void goto_symext::symex_from_entry_point_of(
296304
initialize_entry_point(
297305
state,
298306
get_goto_function,
307+
goto_functionst::entry_point(),
299308
start_function->body.instructions.begin(),
300309
prev(start_function->body.instructions.end()));
301310

src/goto-symex/symex_target.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,26 @@ class symex_targett
2929
struct sourcet
3030
{
3131
unsigned thread_nr;
32+
irep_idt function;
3233
goto_programt::const_targett pc;
3334
bool is_set;
3435

35-
sourcet():
36-
thread_nr(0),
37-
is_set(false)
36+
sourcet() : thread_nr(0), function(irep_idt()), is_set(false)
3837
{
3938
}
4039

41-
explicit sourcet(
42-
goto_programt::const_targett _pc):
43-
thread_nr(0),
44-
pc(_pc),
45-
is_set(true)
40+
sourcet(const irep_idt &_function, goto_programt::const_targett _pc)
41+
: thread_nr(0), function(_function), pc(_pc), is_set(true)
4642
{
4743
}
4844

49-
explicit sourcet(const goto_programt &_goto_program):
50-
thread_nr(0),
51-
pc(_goto_program.instructions.begin()),
52-
is_set(true)
45+
explicit sourcet(
46+
const irep_idt &_function,
47+
const goto_programt &_goto_program)
48+
: thread_nr(0),
49+
function(_function),
50+
pc(_goto_program.instructions.begin()),
51+
is_set(true)
5352
{
5453
}
5554
};

src/goto-symex/symex_target_equation.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,10 @@ void symex_target_equationt::SSA_stept::output(
776776
switch(type)
777777
{
778778
case goto_trace_stept::typet::ASSERT:
779-
out << "ASSERT " << from_expr(ns, source.pc->function, cond_expr) << '\n';
779+
out << "ASSERT " << from_expr(ns, source.function, cond_expr) << '\n';
780780
break;
781781
case goto_trace_stept::typet::ASSUME:
782-
out << "ASSUME " << from_expr(ns, source.pc->function, cond_expr) << '\n';
782+
out << "ASSUME " << from_expr(ns, source.function, cond_expr) << '\n';
783783
break;
784784
case goto_trace_stept::typet::LOCATION:
785785
out << "LOCATION" << '\n'; break;
@@ -790,7 +790,7 @@ void symex_target_equationt::SSA_stept::output(
790790

791791
case goto_trace_stept::typet::DECL:
792792
out << "DECL" << '\n';
793-
out << from_expr(ns, source.pc->function, ssa_lhs) << '\n';
793+
out << from_expr(ns, source.function, ssa_lhs) << '\n';
794794
break;
795795

796796
case goto_trace_stept::typet::ASSIGNMENT:
@@ -844,22 +844,22 @@ void symex_target_equationt::SSA_stept::output(
844844
case goto_trace_stept::typet::MEMORY_BARRIER:
845845
out << "MEMORY_BARRIER\n"; break;
846846
case goto_trace_stept::typet::GOTO:
847-
out << "IF " << from_expr(ns, source.pc->function, cond_expr) << " GOTO\n";
847+
out << "IF " << from_expr(ns, source.function, cond_expr) << " GOTO\n";
848848
break;
849849

850850
default: UNREACHABLE;
851851
}
852852

853853
if(is_assert() || is_assume() || is_assignment() || is_constraint())
854-
out << from_expr(ns, source.pc->function, cond_expr) << '\n';
854+
out << from_expr(ns, source.function, cond_expr) << '\n';
855855

856856
if(is_assert() || is_constraint())
857857
out << comment << '\n';
858858

859859
if(is_shared_read() || is_shared_write())
860-
out << from_expr(ns, source.pc->function, ssa_lhs) << '\n';
860+
out << from_expr(ns, source.function, ssa_lhs) << '\n';
861861

862-
out << "Guard: " << from_expr(ns, source.pc->function, guard) << '\n';
862+
out << "Guard: " << from_expr(ns, source.function, guard) << '\n';
863863
}
864864

865865
void symex_target_equationt::SSA_stept::output(std::ostream &out) const

0 commit comments

Comments
 (0)