Skip to content

Commit 4ad3eab

Browse files
committed
make-function-assume-false command line option
Blocks all paths through a function by replacing the function calls with assume_false. This is similar to --undefined-function-is-assume-false, but gives the flexibility to havoc undefined functions and block specific functions without needing multiple calls to goto-instrument. Needed for aggressive slicer work
1 parent 1821b1a commit 4ad3eab

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

src/goto-instrument/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ SRC = accelerate/accelerate.cpp \
3434
interrupt.cpp \
3535
k_induction.cpp \
3636
loop_utils.cpp \
37+
make_function_assume_false.cpp \
3738
mmio.cpp \
3839
model_argc_argv.cpp \
3940
nondet_static.cpp \

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Author: Daniel Kroening, kroening@kroening.com
9797
#include "model_argc_argv.h"
9898
#include "undefined_functions.h"
9999
#include "remove_function.h"
100+
#include "make_function_assume_false.h"
100101
#include "splice_call.h"
101102

102103
void goto_instrument_parse_optionst::eval_verbosity()
@@ -939,6 +940,14 @@ void goto_instrument_parse_optionst::instrument_goto_program()
939940
get_message_handler());
940941
}
941942

943+
if(cmdline.isset("make-function-assume-false"))
944+
{
945+
make_functions_assume_false(
946+
goto_model,
947+
cmdline.get_values("make-function-assume-false"),
948+
get_message_handler());
949+
}
950+
942951
// we add the library in some cases, as some analyses benefit
943952

944953
if(cmdline.isset("add-library") ||
@@ -1521,6 +1530,8 @@ void goto_instrument_parse_optionst::help()
15211530
" --model-argc-argv <n> model up to <n> command line arguments\n"
15221531
// NOLINTNEXTLINE(whitespace/line_length)
15231532
" --remove-function-body <f> remove the implementation of function <f> (may be repeated)\n"
1533+
" --make-function-assume-false <f>\n"
1534+
" replace calls to function <f> with assume(false) (may be repeated)\n" // NOLINT(*)
15241535
"\n"
15251536
"Other options:\n"
15261537
" --no-system-headers with --dump-c/--dump-cpp: generate C source expanding libc includes\n" // NOLINT(*)

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Author: Daniel Kroening, kroening@kroening.com
7878
"(show-threaded)(list-calls-args)(print-path-lengths)" \
7979
"(undefined-function-is-assume-false)" \
8080
"(remove-function-body):"\
81+
"(make-function-assume-false):"\
8182
"(splice-call):" \
8283

8384

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*******************************************************************\
2+
3+
Module: Make function assume false
4+
5+
Author: Elizabeth Polgreen
6+
7+
Date: November 2017
8+
9+
\*******************************************************************/
10+
11+
/// \file
12+
/// Make function assume false
13+
14+
#include "make_function_assume_false.h"
15+
16+
#include <util/message.h>
17+
18+
#include <goto-programs/goto_model.h>
19+
20+
/// \brief Replace calls to the function with assume(false).
21+
/// This effectively blocks any paths through the function
22+
/// or depending on return values from the function.
23+
/// \param goto_model input program to be modifier
24+
/// \param identifier name of function to block
25+
/// \param message_handler Error/status output
26+
void make_function_assume_false(
27+
goto_modelt &goto_model,
28+
const irep_idt &identifier,
29+
message_handlert &message_handler)
30+
{
31+
messaget message(message_handler);
32+
33+
goto_functionst::function_mapt::iterator entry =
34+
goto_model.goto_functions.function_map.find(identifier);
35+
36+
if(entry==goto_model.goto_functions.function_map.end())
37+
{
38+
message.error() << "No function " << identifier
39+
<< " in goto program" << messaget::eom;
40+
return;
41+
}
42+
else if(entry->second.is_inlined())
43+
{
44+
message.warning() << "Function " << identifier << " is inlined, "
45+
<< "instantiations will not be blocked"
46+
<< messaget::eom;
47+
}
48+
else
49+
{
50+
message.status() << "Blocking all calls to " << identifier << messaget::eom;
51+
52+
Forall_goto_functions(it, goto_model.goto_functions)
53+
{
54+
Forall_goto_program_instructions(iit, it->second.body)
55+
{
56+
goto_programt::instructiont &ins = *iit;
57+
58+
if(!ins.is_function_call())
59+
continue;
60+
61+
const code_function_callt &call = to_code_function_call(ins.code);
62+
63+
if(call.function().id() != ID_symbol)
64+
continue;
65+
66+
if(to_symbol_expr(call.function()).get_identifier() == identifier)
67+
{
68+
ins.make_assumption(false_exprt());
69+
ins.source_location.set_comment(
70+
"`"+id2string(identifier)+"'"
71+
" is marked unusable by --make-function-assume-false");
72+
}
73+
}
74+
}
75+
}
76+
}
77+
78+
/// \brief Replace calls to any functions in the list
79+
/// "functions" with assume(false).
80+
/// This effectively blocks any paths through the function
81+
/// or depending on return values from the function.
82+
/// \param functions list of function names to block
83+
/// \param goto_model input program to be modifier
84+
/// \param message_handler Error/status output
85+
void make_functions_assume_false(
86+
goto_modelt &goto_model,
87+
const std::list<std::string> &functions,
88+
message_handlert &message_handler)
89+
{
90+
messaget message(message_handler);
91+
for(const auto &func : functions)
92+
{
93+
make_function_assume_false(goto_model, func, message_handler);
94+
}
95+
}
96+
97+
98+
99+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************\
2+
3+
Module: Make function assume false
4+
5+
Author: Elizabeth Polgreen
6+
7+
Date: November 2017
8+
9+
\*******************************************************************/
10+
11+
/// \file
12+
/// Make function assume false
13+
14+
#ifndef CPROVER_GOTO_INSTRUMENT_MAKE_FUNCTION_ASSUME_FALSE_H
15+
#define CPROVER_GOTO_INSTRUMENT_MAKE_FUNCTION_ASSUME_FALSE_H
16+
17+
#include <list>
18+
#include <string>
19+
20+
#include <util/irep.h>
21+
22+
class goto_modelt;
23+
class message_handlert;
24+
25+
void make_functions_assume_false(
26+
goto_modelt &,
27+
const std::list<std::string> &names,
28+
message_handlert &);
29+
30+
31+
32+
#endif /* CPROVER_GOTO_INSTRUMENT_MAKE_FUNCTION_ASSUME_FALSE_H */

0 commit comments

Comments
 (0)