Skip to content

Commit e2cd2f3

Browse files
authored
Merge pull request #3844 from tautschnig/function-symex
goto-symex: use function and called_function fields [blocks: #3126]
2 parents fd3d187 + f33f64e commit e2cd2f3

21 files changed

+92
-84
lines changed

src/goto-checker/symex_bmc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void symex_bmct::symex_step(
6969
record_coverage &&
7070
// avoid an invalid iterator in state.source.pc
7171
(!cur_pc->is_end_function() ||
72-
state.source.function != goto_functionst::entry_point()))
72+
state.source.function_id != goto_functionst::entry_point()))
7373
{
7474
// forward goto will effectively be covered via phi function,
7575
// which does not invoke symex_step; as symex_step is called
@@ -110,7 +110,7 @@ bool symex_bmct::should_stop_unwind(
110110
const goto_symex_statet::call_stackt &context,
111111
unsigned unwind)
112112
{
113-
const irep_idt id = goto_programt::loop_id(*source.pc);
113+
const irep_idt id = goto_programt::loop_id(source.function_id, *source.pc);
114114

115115
tvt abort_unwind_decision;
116116
unsigned this_loop_limit = std::numeric_limits<unsigned>::max();

src/goto-instrument/unwind.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ void goto_unwindt::unwind(
288288
}
289289

290290
PRECONDITION(!function_id.empty());
291-
const irep_idt loop_id =
292-
id2string(function_id) + "." + std::to_string(i_it->loop_number);
291+
const irep_idt loop_id = goto_programt::loop_id(function_id, *i_it);
293292

294293
auto limit=unwindset.get_limit(loop_id, 0);
295294

src/goto-programs/goto_program.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,10 @@ class goto_programt
694694
void update();
695695

696696
/// Human-readable loop name
697-
static irep_idt loop_id(const instructiont &instruction)
697+
static irep_idt
698+
loop_id(const irep_idt &function_id, const instructiont &instruction)
698699
{
699-
return id2string(instruction.function)+"."+
700+
return id2string(function_id) + "." +
700701
std::to_string(instruction.loop_number);
701702
}
702703

src/goto-programs/goto_trace.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ state_location(const goto_trace_stept &state, const namespacet &ns)
292292
if(!source_location.get_file().empty())
293293
result += "file " + id2string(source_location.get_file());
294294

295-
if(!state.function.empty())
295+
if(!state.function_id.empty())
296296
{
297-
const symbolt &symbol = ns.lookup(state.function);
297+
const symbolt &symbol = ns.lookup(state.function_id);
298298
if(!result.empty())
299299
result += ' ';
300300
result += "function " + id2string(symbol.display_name());
@@ -333,7 +333,7 @@ void show_state_header(
333333

334334
if(options.show_code)
335335
{
336-
out << as_string(ns, state.function, *state.pc) << '\n';
336+
out << as_string(ns, state.function_id, *state.pc) << '\n';
337337
out << "----------------------------------------------------" << '\n';
338338
}
339339
}
@@ -387,7 +387,10 @@ void show_compact_goto_trace(
387387
out << " " << messaget::red << step.comment << messaget::reset << '\n';
388388

389389
if(step.pc->is_assert())
390-
out << " " << from_expr(ns, step.function, step.pc->guard) << '\n';
390+
{
391+
out << " " << from_expr(ns, step.function_id, step.pc->guard)
392+
<< '\n';
393+
}
391394

392395
out << '\n';
393396
}
@@ -442,7 +445,7 @@ void show_compact_goto_trace(
442445
{
443446
auto arg_strings = make_range(step.function_arguments)
444447
.map([&ns, &step](const exprt &arg) {
445-
return from_expr(ns, step.function, arg);
448+
return from_expr(ns, step.function_id, arg);
446449
});
447450

448451
out << '(';
@@ -507,7 +510,10 @@ void show_full_goto_trace(
507510
out << " " << messaget::red << step.comment << messaget::reset << '\n';
508511

509512
if(step.pc->is_assert())
510-
out << " " << from_expr(ns, step.function, step.pc->guard) << '\n';
513+
{
514+
out << " " << from_expr(ns, step.function_id, step.pc->guard)
515+
<< '\n';
516+
}
511517

512518
out << '\n';
513519
}
@@ -522,7 +528,10 @@ void show_full_goto_trace(
522528
out << " " << step.pc->source_location << '\n';
523529

524530
if(step.pc->is_assume())
525-
out << " " << from_expr(ns, step.function, step.pc->guard) << '\n';
531+
{
532+
out << " " << from_expr(ns, step.function_id, step.pc->guard)
533+
<< '\n';
534+
}
526535

527536
out << '\n';
528537
}
@@ -592,7 +601,7 @@ void show_full_goto_trace(
592601
if(l_it!=step.io_args.begin())
593602
out << ';';
594603

595-
out << ' ' << from_expr(ns, step.function, *l_it);
604+
out << ' ' << from_expr(ns, step.function_id, *l_it);
596605

597606
// the binary representation
598607
out << " (" << trace_numeric_value(*l_it, ns, options) << ')';
@@ -614,7 +623,7 @@ void show_full_goto_trace(
614623
if(l_it!=step.io_args.begin())
615624
out << ';';
616625

617-
out << ' ' << from_expr(ns, step.function, *l_it);
626+
out << ' ' << from_expr(ns, step.function_id, *l_it);
618627

619628
// the binary representation
620629
out << " (" << trace_numeric_value(*l_it, ns, options) << ')';
@@ -638,7 +647,7 @@ void show_full_goto_trace(
638647
else
639648
out << ", ";
640649

641-
out << from_expr(ns, step.function, arg);
650+
out << from_expr(ns, step.function_id, arg);
642651
}
643652

644653
out << ") (depth " << function_depth << ") ####\n";
@@ -649,7 +658,7 @@ void show_full_goto_trace(
649658
function_depth--;
650659
if(options.show_function_calls)
651660
{
652-
out << "\n#### Function return from " << step.function << " (depth "
661+
out << "\n#### Function return from " << step.function_id << " (depth "
653662
<< function_depth << ") ####\n";
654663
}
655664
break;
@@ -732,7 +741,7 @@ static void show_goto_stack_trace(
732741
else
733742
out << ", ";
734743

735-
out << from_expr(ns, step.function, arg);
744+
out << from_expr(ns, step.function_id, arg);
736745
}
737746

738747
out << ')';

src/goto-programs/goto_trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class goto_trace_stept
8888

8989
// The instruction that created this step
9090
// (function calls are in the caller, function returns are in the callee)
91-
irep_idt function;
91+
irep_idt function_id;
9292
goto_programt::const_targett pc;
9393

9494
// this transition done by given thread number

src/goto-programs/graphml_witness.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace)
285285
{
286286
xmlt &val=edge.new_element("data");
287287
val.set_attribute("key", "assumption");
288-
val.data = from_expr(ns, it->function, it->full_lhs) + " = " +
289-
from_expr(ns, it->function, it->full_lhs_value) + ";";
288+
val.data = from_expr(ns, it->function_id, it->full_lhs) + " = " +
289+
from_expr(ns, it->function_id, it->full_lhs_value) + ";";
290290

291291
xmlt &val_s=edge.new_element("data");
292292
val_s.set_attribute("key", "assumption.scope");
@@ -297,9 +297,10 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace)
297297
{
298298
xmlt &val=edge.new_element("data");
299299
val.set_attribute("key", "sourcecode");
300-
const std::string cond = from_expr(ns, it->function, it->cond_expr);
300+
const std::string cond =
301+
from_expr(ns, it->function_id, it->cond_expr);
301302
const std::string neg_cond =
302-
from_expr(ns, it->function, not_exprt(it->cond_expr));
303+
from_expr(ns, it->function_id, not_exprt(it->cond_expr));
303304
val.data="["+(it->cond_value ? cond : neg_cond)+"]";
304305

305306
#if 0
@@ -483,7 +484,7 @@ void graphml_witnesst::operator()(const symex_target_equationt &equation)
483484
xmlt &val=edge.new_element("data");
484485
val.set_attribute("key", "sourcecode");
485486
const std::string cond =
486-
from_expr(ns, it->source.function, it->cond_expr);
487+
from_expr(ns, it->source.function_id, it->cond_expr);
487488
val.data="["+cond+"]";
488489
}
489490

src/goto-programs/json_goto_trace.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void convert_output(
179179
// Recovering the mode from the function
180180
irep_idt mode;
181181
const symbolt *function_name;
182-
if(ns.lookup(step.function, function_name))
182+
if(ns.lookup(step.function_id, function_name))
183183
// Failed to find symbol
184184
mode = ID_unknown;
185185
else
@@ -221,7 +221,7 @@ void convert_input(
221221
// Recovering the mode from the function
222222
irep_idt mode;
223223
const symbolt *function_name;
224-
if(ns.lookup(step.function, function_name))
224+
if(ns.lookup(step.function_id, function_name))
225225
// Failed to find symbol
226226
mode = ID_unknown;
227227
else
@@ -265,7 +265,7 @@ void convert_return(
265265

266266
const irep_idt &function_identifier =
267267
(step.type == goto_trace_stept::typet::FUNCTION_CALL) ? step.called_function
268-
: step.function;
268+
: step.function_id;
269269

270270
const symbolt &symbol = ns.lookup(function_identifier);
271271
json_call_return["function"] =

src/goto-programs/loop_ids.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void show_loop_ids(
2525

2626
void show_loop_ids(
2727
ui_message_handlert::uit ui,
28-
const irep_idt &function_identifier,
28+
const irep_idt &function_id,
2929
const goto_programt &goto_program)
3030
{
3131
switch(ui)
@@ -36,9 +36,8 @@ void show_loop_ids(
3636
{
3737
if(it->is_backwards_goto())
3838
{
39-
unsigned loop_id=it->loop_number;
40-
41-
std::cout << "Loop " << function_identifier << "." << loop_id << ":"
39+
std::cout << "Loop " << goto_programt::loop_id(function_id, *it)
40+
<< ":"
4241
<< "\n";
4342

4443
std::cout << " " << it->source_location << "\n";
@@ -53,9 +52,7 @@ void show_loop_ids(
5352
{
5453
if(it->is_backwards_goto())
5554
{
56-
unsigned loop_id=it->loop_number;
57-
std::string id =
58-
id2string(function_identifier) + "." + std::to_string(loop_id);
55+
std::string id = id2string(goto_programt::loop_id(function_id, *it));
5956

6057
xmlt xml_loop("loop", {{"name", id}}, {});
6158
xml_loop.new_element("loop-id").data=id;
@@ -72,7 +69,7 @@ void show_loop_ids(
7269

7370
void show_loop_ids_json(
7471
ui_message_handlert::uit ui,
75-
const irep_idt &function_identifier,
72+
const irep_idt &function_id,
7673
const goto_programt &goto_program,
7774
json_arrayt &loops)
7875
{
@@ -82,9 +79,7 @@ void show_loop_ids_json(
8279
{
8380
if(it->is_backwards_goto())
8481
{
85-
unsigned loop_id=it->loop_number;
86-
std::string id =
87-
id2string(function_identifier) + "." + std::to_string(loop_id);
82+
std::string id = id2string(goto_programt::loop_id(function_id, *it));
8883

8984
loops.push_back(
9085
json_objectt({{"name", json_stringt(id)},

src/goto-programs/loop_ids.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void show_loop_ids(
2626

2727
void show_loop_ids(
2828
ui_message_handlert::uit,
29-
const irep_idt &function_identifier,
29+
const irep_idt &function_id,
3030
const goto_programt &);
3131

3232
#endif // CPROVER_GOTO_PROGRAMS_LOOP_IDS_H

src/goto-programs/xml_goto_trace.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void convert(
127127
for(const auto &arg : step.io_args)
128128
{
129129
xml_output.new_element("value").data =
130-
from_expr(ns, step.function, arg);
130+
from_expr(ns, step.function_id, arg);
131131
xml_output.new_element("value_expression").
132132
new_element(xml(arg, ns));
133133
}
@@ -146,7 +146,7 @@ void convert(
146146
for(const auto &arg : step.io_args)
147147
{
148148
xml_input.new_element("value").data =
149-
from_expr(ns, step.function, arg);
149+
from_expr(ns, step.function_id, arg);
150150
xml_input.new_element("value_expression").
151151
new_element(xml(arg, ns));
152152
}
@@ -186,11 +186,11 @@ void convert(
186186
xml_call_return.set_attribute("thread", std::to_string(step.thread_nr));
187187
xml_call_return.set_attribute("step_nr", std::to_string(step.step_nr));
188188

189-
const symbolt &symbol = ns.lookup(step.function);
189+
const symbolt &symbol = ns.lookup(step.function_id);
190190
xmlt &xml_function=xml_call_return.new_element("function");
191191
xml_function.set_attribute(
192192
"display_name", id2string(symbol.display_name()));
193-
xml_function.set_attribute("identifier", id2string(step.function));
193+
xml_function.set_attribute("identifier", id2string(step.function_id));
194194
xml_function.new_element()=xml(symbol.location);
195195

196196
if(xml_location.name!="")

src/goto-symex/build_goto_trace.cpp

Lines changed: 2 additions & 2 deletions
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.function == goto_functionst::entry_point())
159+
if(SSA_step.source.function_id == 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
@@ -304,7 +304,7 @@ void build_goto_trace(
304304

305305
goto_trace_step.thread_nr = SSA_step.source.thread_nr;
306306
goto_trace_step.pc = SSA_step.source.pc;
307-
goto_trace_step.function = SSA_step.source.function;
307+
goto_trace_step.function_id = SSA_step.source.function_id;
308308
if(SSA_step.is_assert())
309309
{
310310
goto_trace_step.comment = SSA_step.comment;

src/goto-symex/goto_symex_state.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ void goto_symex_statet::print_backtrace(std::ostream &out) const
759759
return;
760760
}
761761

762-
out << source.pc->function << " " << source.pc->location_number << "\n";
762+
out << source.function_id << " " << source.pc->location_number << "\n";
763763

764764
for(auto stackit = threads[source.thread_nr].call_stack.rbegin(),
765765
stackend = threads[source.thread_nr].call_stack.rend();
@@ -769,7 +769,7 @@ void goto_symex_statet::print_backtrace(std::ostream &out) const
769769
const auto &frame = *stackit;
770770
if(frame.calling_location.is_set)
771771
{
772-
out << frame.calling_location.pc->function << " "
772+
out << frame.calling_location.function_id << " "
773773
<< frame.calling_location.pc->location_number << "\n";
774774
}
775775
}

src/goto-symex/show_program.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ static void show_step(
2828
const std::string &annotation,
2929
std::size_t &count)
3030
{
31-
const irep_idt &function = step.source.function;
31+
const irep_idt &function_id = step.source.function_id;
3232

3333
std::string string_value = (step.is_shared_read() || step.is_shared_write())
34-
? from_expr(ns, function, step.ssa_lhs)
35-
: from_expr(ns, function, step.cond_expr);
34+
? from_expr(ns, function_id, step.ssa_lhs)
35+
: from_expr(ns, function_id, step.cond_expr);
3636
std::cout << '(' << count << ") ";
3737
if(annotation.empty())
3838
std::cout << string_value;
@@ -42,7 +42,7 @@ static void show_step(
4242

4343
if(!step.guard.is_true())
4444
{
45-
const std::string guard_string = from_expr(ns, function, step.guard);
45+
const std::string guard_string = from_expr(ns, function_id, step.guard);
4646
std::cout << std::string(std::to_string(count).size() + 3, ' ');
4747
std::cout << "guard: " << guard_string << '\n';
4848
}

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void goto_symext::symex_allocate(
5656

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

src/goto-symex/symex_dereference.cpp

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

258258
if(state.threads.size() == 1)
259259
{
260-
const irep_idt &expr_function = state.source.function;
260+
const irep_idt &expr_function = state.source.function_id;
261261
if(!expr_function.empty())
262262
{
263263
state.get_original_name(to_check);

0 commit comments

Comments
 (0)