Skip to content

Commit 0359a87

Browse files
committed
remove_calls_no_body: generate status output
Use of this functionality will make symex warnings about functions without body go away. To make up for this, at least status output should be produced to ensure that this possible soundness issue of the verification result can be caught.
1 parent 46e69a4 commit 0359a87

File tree

9 files changed

+104
-40
lines changed

9 files changed

+104
-40
lines changed

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -962,18 +962,24 @@ bool jbmc_parse_optionst::process_goto_functions(
962962
log.status() << "Performing a forwards-backwards reachability slice"
963963
<< messaget::eom;
964964
if(cmdline.isset("property"))
965-
reachability_slicer(goto_model, cmdline.get_values("property"), true);
965+
{
966+
reachability_slicer(
967+
goto_model, cmdline.get_values("property"), true, ui_message_handler);
968+
}
966969
else
967-
reachability_slicer(goto_model, true);
970+
reachability_slicer(goto_model, true, ui_message_handler);
968971
}
969972

970973
if(cmdline.isset("reachability-slice"))
971974
{
972975
log.status() << "Performing a reachability slice" << messaget::eom;
973976
if(cmdline.isset("property"))
974-
reachability_slicer(goto_model, cmdline.get_values("property"));
977+
{
978+
reachability_slicer(
979+
goto_model, cmdline.get_values("property"), ui_message_handler);
980+
}
975981
else
976-
reachability_slicer(goto_model);
982+
reachability_slicer(goto_model, ui_message_handler);
977983
}
978984

979985
// full slice?

regression/goto-instrument/reachability-slice/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
33
--reachability-slice
4+
Removing call to undefined_function, which has no body
45
^VERIFICATION FAILED$
56
^EXIT=10$
67
^SIGNAL=0$

src/cbmc/cbmc_parse_options.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -944,19 +944,29 @@ bool cbmc_parse_optionst::process_goto_program(
944944
log.status() << "Performing a forwards-backwards reachability slice"
945945
<< messaget::eom;
946946
if(options.is_set("property"))
947+
{
947948
reachability_slicer(
948-
goto_model, options.get_list_option("property"), true);
949+
goto_model,
950+
options.get_list_option("property"),
951+
true,
952+
log.get_message_handler());
953+
}
949954
else
950-
reachability_slicer(goto_model, true);
955+
reachability_slicer(goto_model, true, log.get_message_handler());
951956
}
952957

953958
if(options.get_bool_option("reachability-slice"))
954959
{
955960
log.status() << "Performing a reachability slice" << messaget::eom;
956961
if(options.is_set("property"))
957-
reachability_slicer(goto_model, options.get_list_option("property"));
962+
{
963+
reachability_slicer(
964+
goto_model,
965+
options.get_list_option("property"),
966+
log.get_message_handler());
967+
}
958968
else
959-
reachability_slicer(goto_model);
969+
reachability_slicer(goto_model, log.get_message_handler());
960970
}
961971

962972
// full slice?

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ int goto_instrument_parse_optionst::doit()
841841
log.status() << "Removing calls to functions without a body"
842842
<< messaget::eom;
843843
remove_calls_no_bodyt remove_calls_no_body;
844-
remove_calls_no_body(goto_model.goto_functions);
844+
remove_calls_no_body(goto_model.goto_functions, ui_message_handler);
845845

846846
log.status() << "Accelerating" << messaget::eom;
847847
guard_managert guard_manager;
@@ -1248,7 +1248,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
12481248
<< messaget::eom;
12491249

12501250
remove_calls_no_bodyt remove_calls_no_body;
1251-
remove_calls_no_body(goto_model.goto_functions);
1251+
remove_calls_no_body(goto_model.goto_functions, ui_message_handler);
12521252

12531253
goto_model.goto_functions.update();
12541254
goto_model.goto_functions.compute_loop_numbers();
@@ -1605,9 +1605,12 @@ void goto_instrument_parse_optionst::instrument_goto_program()
16051605
goto_model.goto_functions.update();
16061606

16071607
if(cmdline.isset("property"))
1608-
reachability_slicer(goto_model, cmdline.get_values("property"));
1608+
{
1609+
reachability_slicer(
1610+
goto_model, cmdline.get_values("property"), ui_message_handler);
1611+
}
16091612
else
1610-
reachability_slicer(goto_model);
1613+
reachability_slicer(goto_model, ui_message_handler);
16111614
}
16121615

16131616
if(cmdline.isset("fp-reachability-slice"))
@@ -1617,7 +1620,9 @@ void goto_instrument_parse_optionst::instrument_goto_program()
16171620
log.status() << "Performing a function pointer reachability slice"
16181621
<< messaget::eom;
16191622
function_path_reachability_slicer(
1620-
goto_model, cmdline.get_comma_separated_values("fp-reachability-slice"));
1623+
goto_model,
1624+
cmdline.get_comma_separated_values("fp-reachability-slice"),
1625+
ui_message_handler);
16211626
}
16221627

16231628
// full slice?
@@ -1690,9 +1695,12 @@ void goto_instrument_parse_optionst::instrument_goto_program()
16901695

16911696
log.status() << "Performing a reachability slice" << messaget::eom;
16921697
if(cmdline.isset("property"))
1693-
reachability_slicer(goto_model, cmdline.get_values("property"));
1698+
{
1699+
reachability_slicer(
1700+
goto_model, cmdline.get_values("property"), ui_message_handler);
1701+
}
16941702
else
1695-
reachability_slicer(goto_model);
1703+
reachability_slicer(goto_model, ui_message_handler);
16961704
}
16971705

16981706
if(cmdline.isset("ensure-one-backedge-per-target"))

src/goto-instrument/reachability_slicer.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ Author: Daniel Kroening, [email protected]
3030
void reachability_slicert::operator()(
3131
goto_functionst &goto_functions,
3232
const slicing_criteriont &criterion,
33-
bool include_forward_reachability)
33+
bool include_forward_reachability,
34+
message_handlert &message_handler)
3435
{
3536
// Replace function calls without body by non-deterministic return values to
3637
// ensure the CFG does not consider instructions after such a call to be
3738
// unreachable.
3839
remove_calls_no_bodyt remove_calls_no_body;
39-
remove_calls_no_body(goto_functions);
40+
remove_calls_no_body(goto_functions, message_handler);
4041
goto_functions.update();
4142

4243
cfg(goto_functions);
@@ -392,13 +393,18 @@ void reachability_slicert::slice(goto_functionst &goto_functions)
392393
/// \param include_forward_reachability: Determines if only instructions
393394
/// from which the criterion is reachable should be kept (false) or also
394395
/// those reachable from the criterion (true)
396+
/// \param message_handler: message handler
395397
void reachability_slicer(
396398
goto_modelt &goto_model,
397-
const bool include_forward_reachability)
399+
const bool include_forward_reachability,
400+
message_handlert &message_handler)
398401
{
399402
reachability_slicert s;
400403
assert_criteriont a;
401-
s(goto_model.goto_functions, a, include_forward_reachability);
404+
s(goto_model.goto_functions,
405+
a,
406+
include_forward_reachability,
407+
message_handler);
402408
}
403409

404410
/// Perform reachability slicing on goto_model for selected properties.
@@ -408,34 +414,42 @@ void reachability_slicer(
408414
/// \param include_forward_reachability: Determines if only instructions
409415
/// from which the criterion is reachable should be kept (false) or also
410416
/// those reachable from the criterion (true)
417+
/// \param message_handler: message handler
411418
void reachability_slicer(
412419
goto_modelt &goto_model,
413420
const std::list<std::string> &properties,
414-
const bool include_forward_reachability)
421+
const bool include_forward_reachability,
422+
message_handlert &message_handler)
415423
{
416424
reachability_slicert s;
417425
properties_criteriont p(properties);
418-
s(goto_model.goto_functions, p, include_forward_reachability);
426+
s(goto_model.goto_functions,
427+
p,
428+
include_forward_reachability,
429+
message_handler);
419430
}
420431

421432
/// Perform reachability slicing on goto_model for selected functions.
422433
/// \param goto_model: Goto program to slice
423434
/// \param functions_list: The functions relevant for the slicing (i.e. starting
424435
/// point for the search in the CFG). Anything that is reachable in the CFG
425436
/// starting from these functions will be kept.
437+
/// \param message_handler: message handler
426438
void function_path_reachability_slicer(
427439
goto_modelt &goto_model,
428-
const std::list<std::string> &functions_list)
440+
const std::list<std::string> &functions_list,
441+
message_handlert &message_handler)
429442
{
430443
for(const auto &function : functions_list)
431444
{
432445
in_function_criteriont matching_criterion(function);
433446
reachability_slicert slicer;
434-
slicer(goto_model.goto_functions, matching_criterion, true);
447+
slicer(
448+
goto_model.goto_functions, matching_criterion, true, message_handler);
435449
}
436450

437451
remove_calls_no_bodyt remove_calls_no_body;
438-
remove_calls_no_body(goto_model.goto_functions);
452+
remove_calls_no_body(goto_model.goto_functions, message_handler);
439453

440454
goto_model.goto_functions.update();
441455
goto_model.goto_functions.compute_loop_numbers();
@@ -445,19 +459,24 @@ void function_path_reachability_slicer(
445459
/// comprising all properties. Only instructions from which the criterion
446460
/// is reachable will be kept.
447461
/// \param goto_model: Goto program to slice
448-
void reachability_slicer(goto_modelt &goto_model)
462+
/// \param message_handler: message handler
463+
void reachability_slicer(
464+
goto_modelt &goto_model,
465+
message_handlert &message_handler)
449466
{
450-
reachability_slicer(goto_model, false);
467+
reachability_slicer(goto_model, false, message_handler);
451468
}
452469

453470
/// Perform reachability slicing on goto_model for selected properties. Only
454471
/// instructions from which the criterion is reachable will be kept.
455472
/// \param goto_model: Goto program to slice
456473
/// \param properties: The properties relevant for the slicing (i.e. starting
457474
/// point for the search in the cfg)
475+
/// \param message_handler: message handler
458476
void reachability_slicer(
459477
goto_modelt &goto_model,
460-
const std::list<std::string> &properties)
478+
const std::list<std::string> &properties,
479+
message_handlert &message_handler)
461480
{
462-
reachability_slicer(goto_model, properties, false);
481+
reachability_slicer(goto_model, properties, false, message_handler);
463482
}

src/goto-instrument/reachability_slicer.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,30 @@ Author: Daniel Kroening, [email protected]
1616
#include <string>
1717

1818
class goto_modelt;
19+
class message_handlert;
1920

20-
void reachability_slicer(goto_modelt &);
21+
void reachability_slicer(goto_modelt &, message_handlert &);
2122

2223
void reachability_slicer(
2324
goto_modelt &,
24-
const std::list<std::string> &properties);
25+
const std::list<std::string> &properties,
26+
message_handlert &);
2527

2628
void function_path_reachability_slicer(
2729
goto_modelt &goto_model,
28-
const std::list<std::string> &functions_list);
30+
const std::list<std::string> &functions_list,
31+
message_handlert &);
2932

3033
void reachability_slicer(
3134
goto_modelt &,
32-
const bool include_forward_reachability);
35+
const bool include_forward_reachability,
36+
message_handlert &);
3337

3438
void reachability_slicer(
3539
goto_modelt &,
3640
const std::list<std::string> &properties,
37-
const bool include_forward_reachability);
41+
const bool include_forward_reachability,
42+
message_handlert &);
3843

3944
// clang-format off
4045
#define OPT_REACHABILITY_SLICER \

src/goto-instrument/reachability_slicer_class.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected]
1515
#include <goto-programs/goto_program.h>
1616

1717
class goto_functionst;
18+
class message_handlert;
1819
class slicing_criteriont;
1920

2021
class reachability_slicert
@@ -23,7 +24,8 @@ class reachability_slicert
2324
void operator()(
2425
goto_functionst &goto_functions,
2526
const slicing_criteriont &criterion,
26-
bool include_forward_reachability);
27+
bool include_forward_reachability,
28+
message_handlert &);
2729

2830
protected:
2931
struct slicer_entryt

src/goto-programs/remove_calls_no_body.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Poetzl
1212
#include "remove_calls_no_body.h"
1313

1414
#include <util/invariant.h>
15+
#include <util/message.h>
1516
#include <util/std_code.h>
1617

1718
#include "goto_functions.h"
@@ -94,14 +95,21 @@ bool remove_calls_no_bodyt::is_opaque_function_call(
9495
/// \param goto_program: goto program to operate on
9596
/// \param goto_functions: all goto functions; for looking up functions which
9697
/// the goto program may call
97-
void remove_calls_no_bodyt::
98-
operator()(goto_programt &goto_program, const goto_functionst &goto_functions)
98+
/// \param message_handler: message handler
99+
void remove_calls_no_bodyt::operator()(
100+
goto_programt &goto_program,
101+
const goto_functionst &goto_functions,
102+
message_handlert &message_handler)
99103
{
100104
for(goto_programt::targett it = goto_program.instructions.begin();
101105
it != goto_program.instructions.end();) // no it++
102106
{
103107
if(is_opaque_function_call(it, goto_functions))
104108
{
109+
messaget log{message_handler};
110+
log.status() << "Removing call to "
111+
<< to_symbol_expr(it->call_function()).get_identifier()
112+
<< ", which has no body" << messaget::eom;
105113
remove_call_no_body(
106114
goto_program, it, it->call_lhs(), it->call_arguments());
107115
}
@@ -116,10 +124,13 @@ operator()(goto_programt &goto_program, const goto_functionst &goto_functions)
116124
/// of the arguments of the call and a nondet assignment to the variable taking
117125
/// the return value.
118126
/// \param goto_functions: goto functions to operate on
119-
void remove_calls_no_bodyt::operator()(goto_functionst &goto_functions)
127+
/// \param message_handler: message handler
128+
void remove_calls_no_bodyt::operator()(
129+
goto_functionst &goto_functions,
130+
message_handlert &message_handler)
120131
{
121132
for(auto &gf_entry : goto_functions.function_map)
122133
{
123-
(*this)(gf_entry.second.body, goto_functions);
134+
(*this)(gf_entry.second.body, goto_functions, message_handler);
124135
}
125136
}

src/goto-programs/remove_calls_no_body.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Poetzl
1515
#include "goto_program.h"
1616

1717
class goto_functionst;
18+
class message_handlert;
1819

1920
class remove_calls_no_bodyt
2021
{
@@ -32,9 +33,10 @@ class remove_calls_no_bodyt
3233
public:
3334
void operator()(
3435
goto_programt &goto_program,
35-
const goto_functionst &goto_functions);
36+
const goto_functionst &goto_functions,
37+
message_handlert &);
3638

37-
void operator()(goto_functionst &goto_functions);
39+
void operator()(goto_functionst &goto_functions, message_handlert &);
3840
};
3941

4042
#define OPT_REMOVE_CALLS_NO_BODY "(remove-calls-no-body)"

0 commit comments

Comments
 (0)