Skip to content

Commit cfcb6b1

Browse files
committed
Option --replace-calls to replace function calls with calls to other given functions
1 parent 61a8c30 commit cfcb6b1

File tree

19 files changed

+395
-1
lines changed

19 files changed

+395
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <assert.h>
2+
3+
int f(int a)
4+
{
5+
return a;
6+
}
7+
8+
int g(int b)
9+
{
10+
return b + 1;
11+
}
12+
13+
int main()
14+
{
15+
int r;
16+
17+
r = f(0);
18+
assert(r == 1);
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--replace-calls f:g
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
int f(int a)
3+
{
4+
return a;
5+
}
6+
7+
int g(int b)
8+
{
9+
return b + 1;
10+
}
11+
12+
int main()
13+
{
14+
int r;
15+
16+
r = f(0);
17+
assert(r == 1);
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--replace-calls f:g
4+
g\(0\);
5+
^VERIFICATION SUCCESSFUL$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
f\(0\);
10+
^warning: ignoring
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
int f()
3+
{
4+
return 0;
5+
}
6+
7+
int g()
8+
{
9+
return 1;
10+
}
11+
12+
int h()
13+
{
14+
return 2;
15+
}
16+
17+
int i()
18+
{
19+
return 3;
20+
}
21+
22+
int main()
23+
{
24+
int r;
25+
26+
r = f();
27+
assert(r == 1);
28+
29+
r = h();
30+
assert(r == 3);
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--replace-calls f:g --replace-calls h:i
4+
g\(\);
5+
i\(\);
6+
^VERIFICATION SUCCESSFUL$
7+
^EXIT=0$
8+
^SIGNAL=0$
9+
--
10+
f\(\);
11+
h\(\);
12+
^warning: ignoring
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
int f()
3+
{
4+
return 0;
5+
}
6+
7+
char g()
8+
{
9+
return 1;
10+
}
11+
12+
int main()
13+
{
14+
f();
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--replace-calls f:g
4+
Functions f and g are not type-compatible
5+
^EXIT=11$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
void f(int a)
3+
{
4+
return 0;
5+
}
6+
7+
void g(unsigned a)
8+
{
9+
return 1;
10+
}
11+
12+
int main()
13+
{
14+
f(0);
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--replace-calls f:g
4+
Functions f and g are not type-compatible
5+
^EXIT=11$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
int main()
3+
{
4+
return 0;
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--replace-calls f:g --replace-calls h:f
4+
Function f cannot both be replaced and be a replacement
5+
^EXIT=11$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

src/cbmc/cbmc_parse_options.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
193193
if(cmdline.isset("nondet-static"))
194194
options.set_option("nondet-static", true);
195195

196+
if(cmdline.isset("replace-calls"))
197+
options.set_option("replace-calls", cmdline.get_values("replace-calls"));
198+
196199
if(cmdline.isset("no-simplify"))
197200
options.set_option("simplify", false);
198201

@@ -730,6 +733,12 @@ bool cbmc_parse_optionst::process_goto_program(
730733
goto_model,
731734
options.get_bool_option("pointer-check"));
732735

736+
if(options.is_set("replace-calls"))
737+
{
738+
replace_callst replace_calls;
739+
replace_calls(goto_model, options.get_list_option("replace-calls"));
740+
}
741+
733742
mm_io(goto_model);
734743

735744
// instrument library preconditions
@@ -945,6 +954,7 @@ void cbmc_parse_optionst::help()
945954
"Semantic transformations:\n"
946955
// NOLINTNEXTLINE(whitespace/line_length)
947956
" --nondet-static add nondeterministic initialization of variables with static lifetime\n"
957+
HELP_REPLACE_CALLS
948958
"\n"
949959
"BMC options:\n"
950960
HELP_BMC

src/cbmc/cbmc_parse_options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Author: Daniel Kroening, [email protected]
2121
#include <analyses/goto_check.h>
2222

2323
#include <goto-programs/goto_trace.h>
24+
#include <goto-programs/replace_calls.h>
2425

2526
#include "bmc.h"
2627
#include "xml_interface.h"
@@ -73,6 +74,7 @@ class optionst;
7374
OPT_FLUSH \
7475
"(localize-faults)(localize-faults-method):" \
7576
OPT_GOTO_TRACE \
77+
OPT_REPLACE_CALLS \
7678
"(claim):(show-claims)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)
7779
// clang-format on
7880

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,14 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10631063
do_remove_const_function_pointers_only();
10641064
}
10651065

1066+
if(cmdline.isset("replace-calls"))
1067+
{
1068+
do_indirect_call_and_rtti_removal();
1069+
1070+
replace_callst replace_calls;
1071+
replace_calls(goto_model, cmdline.get_values("replace-calls"));
1072+
}
1073+
10661074
if(cmdline.isset("function-inline"))
10671075
{
10681076
std::string function=cmdline.get_value("function-inline");
@@ -1628,6 +1636,7 @@ void goto_instrument_parse_optionst::help()
16281636
" --model-argc-argv <n> model up to <n> command line arguments\n"
16291637
// NOLINTNEXTLINE(whitespace/line_length)
16301638
" --remove-function-body <f> remove the implementation of function <f> (may be repeated)\n"
1639+
HELP_REPLACE_CALLS
16311640
"\n"
16321641
"Other options:\n"
16331642
" --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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include <goto-programs/goto_functions.h>
2121
#include <goto-programs/remove_calls_no_body.h>
2222
#include <goto-programs/remove_const_function_pointers.h>
23+
#include <goto-programs/replace_calls.h>
2324
#include <goto-programs/show_goto_functions.h>
2425
#include <goto-programs/show_properties.h>
2526

@@ -97,7 +98,8 @@ Author: Daniel Kroening, [email protected]
9798
OPT_REMOVE_CALLS_NO_BODY \
9899
OPT_REPLACE_FUNCTION_BODY \
99100
OPT_GOTO_PROGRAM_STATS \
100-
"(show-local-safe-pointers)(show-safe-dereferences)"
101+
"(show-local-safe-pointers)(show-safe-dereferences)" \
102+
OPT_REPLACE_CALLS
101103

102104
// clang-format on
103105

src/goto-programs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ SRC = adjust_float_expressions.cpp \
6767
wp.cpp \
6868
write_goto_binary.cpp \
6969
xml_goto_trace.cpp \
70+
replace_calls.cpp \
7071
# Empty last line
7172

7273
INCLUDES= -I ..

0 commit comments

Comments
 (0)