Skip to content

Commit f5aff56

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#2705 from danpoe/feature/replace-function-calls
Replace function calls with calls to other functions
2 parents 072b592 + 03fa885 commit f5aff56

File tree

17 files changed

+398
-4
lines changed

17 files changed

+398
-4
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
int f(int a)
2+
{
3+
return a;
4+
}
5+
6+
int g(int b)
7+
{
8+
return b + 1;
9+
}
10+
11+
int main()
12+
{
13+
int r;
14+
15+
r = f(0);
16+
assert(r == 1);
17+
}
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
int f()
2+
{
3+
return 0;
4+
}
5+
6+
int g()
7+
{
8+
return 1;
9+
}
10+
11+
int h()
12+
{
13+
return 2;
14+
}
15+
16+
int i()
17+
{
18+
return 3;
19+
}
20+
21+
int main()
22+
{
23+
int r;
24+
25+
r = f();
26+
assert(r == 1);
27+
28+
r = h();
29+
assert(r == 3);
30+
}
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
int f()
2+
{
3+
return 0;
4+
}
5+
6+
char g()
7+
{
8+
return 1;
9+
}
10+
11+
int main()
12+
{
13+
f();
14+
}
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
void f(int a)
2+
{
3+
return 0;
4+
}
5+
6+
void g(unsigned a)
7+
{
8+
return 1;
9+
}
10+
11+
int main()
12+
{
13+
f(0);
14+
}
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
void g()
2+
{
3+
}
4+
5+
int main()
6+
{
7+
return 0;
8+
}
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
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
int f()
2+
{
3+
return 0;
4+
}
5+
6+
int g()
7+
{
8+
return 1;
9+
}
10+
11+
int main()
12+
{
13+
int (*h)(void);
14+
15+
h = g;
16+
h = f;
17+
18+
int r;
19+
r = h();
20+
assert(r == 1);
21+
22+
return 0;
23+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--replace-calls f:g
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
f\(\);
9+
^warning: ignoring

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: 4 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,9 @@ 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 \
103+
// empty last line
101104

102105
// clang-format on
103106

src/goto-programs/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SRC = adjust_float_expressions.cpp \
66
destructor.cpp \
77
elf_reader.cpp \
88
format_strings.cpp \
9-
initialize_goto_model.cpp \
9+
generate_function_bodies.cpp \
1010
goto_asm.cpp \
1111
goto_clean_expr.cpp \
1212
goto_convert.cpp \
@@ -16,12 +16,13 @@ SRC = adjust_float_expressions.cpp \
1616
goto_convert_side_effect.cpp \
1717
goto_function.cpp \
1818
goto_functions.cpp \
19-
goto_inline.cpp \
2019
goto_inline_class.cpp \
20+
goto_inline.cpp \
2121
goto_program.cpp \
2222
goto_program_template.cpp \
2323
goto_trace.cpp \
2424
graphml_witness.cpp \
25+
initialize_goto_model.cpp \
2526
instrument_preconditions.cpp \
2627
interpreter.cpp \
2728
interpreter_evaluate.cpp \
@@ -50,7 +51,7 @@ SRC = adjust_float_expressions.cpp \
5051
remove_unused_functions.cpp \
5152
remove_vector.cpp \
5253
remove_virtual_functions.cpp \
53-
generate_function_bodies.cpp \
54+
replace_calls.cpp \
5455
resolve_inherited_component.cpp \
5556
safety_checker.cpp \
5657
set_properties.cpp \

0 commit comments

Comments
 (0)