Skip to content

Replace function calls with calls to other functions #2705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions regression/goto-instrument/replace-calls-01/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
int f(int a)
{
return a;
}

int g(int b)
{
return b + 1;
}

int main()
{
int r;

r = f(0);
assert(r == 1);
}
10 changes: 10 additions & 0 deletions regression/goto-instrument/replace-calls-01/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--replace-calls f:g
g\(0\);
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
f\(0\);
^warning: ignoring
30 changes: 30 additions & 0 deletions regression/goto-instrument/replace-calls-02/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
int f()
{
return 0;
}

int g()
{
return 1;
}

int h()
{
return 2;
}

int i()
{
return 3;
}

int main()
{
int r;

r = f();
assert(r == 1);

r = h();
assert(r == 3);
}
12 changes: 12 additions & 0 deletions regression/goto-instrument/replace-calls-02/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--replace-calls f:g --replace-calls h:i
g\(\);
i\(\);
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
f\(\);
h\(\);
^warning: ignoring
14 changes: 14 additions & 0 deletions regression/goto-instrument/replace-calls-03/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int f()
{
return 0;
}

char g()
{
return 1;
}

int main()
{
f();
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/replace-calls-03/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--replace-calls f:g
Functions f and g are not type-compatible
^EXIT=11$
^SIGNAL=0$
--
^warning: ignoring
14 changes: 14 additions & 0 deletions regression/goto-instrument/replace-calls-04/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
void f(int a)
{
return 0;
}

void g(unsigned a)
{
return 1;
}

int main()
{
f(0);
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/replace-calls-04/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--replace-calls f:g
Functions f and g are not type-compatible
^EXIT=11$
^SIGNAL=0$
--
^warning: ignoring
8 changes: 8 additions & 0 deletions regression/goto-instrument/replace-calls-05/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
void g()
{
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove blank line (same in other files)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done (but github doesn't seem to notice).

int main()
{
return 0;
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/replace-calls-05/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--replace-calls f:g --replace-calls h:f
Function f cannot both be replaced and be a replacement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if I replace the entry point (potentially specified by --function)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test involving function pointers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've added a test that involves function pointers.

Regarding the entry point replacement with --function, were you meaning that the error message should be more specific to indicate that it's coming from the replace calls analysis?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is saying the usual 'No entry point found' then this is fine. An invariant violation would not be ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replace calls pass works both when an entry point is present and when not (goto-instrument does not check whether an entry point is present). Also it cannot be used to replace the entry point, as it replaces calls not functions and the entry point is not called by anything.

^EXIT=11$
^SIGNAL=0$
--
^warning: ignoring
23 changes: 23 additions & 0 deletions regression/goto-instrument/replace-calls-06/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
int f()
{
return 0;
}

int g()
{
return 1;
}

int main()
{
int (*h)(void);

h = g;
h = f;

int r;
r = h();
assert(r == 1);

return 0;
}
9 changes: 9 additions & 0 deletions regression/goto-instrument/replace-calls-06/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--replace-calls f:g
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
f\(\);
^warning: ignoring
9 changes: 9 additions & 0 deletions src/goto-instrument/goto_instrument_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,14 @@ void goto_instrument_parse_optionst::instrument_goto_program()
do_remove_const_function_pointers_only();
}

if(cmdline.isset("replace-calls"))
{
do_indirect_call_and_rtti_removal();

replace_callst replace_calls;
replace_calls(goto_model, cmdline.get_values("replace-calls"));
}

if(cmdline.isset("function-inline"))
{
std::string function=cmdline.get_value("function-inline");
Expand Down Expand Up @@ -1628,6 +1636,7 @@ void goto_instrument_parse_optionst::help()
" --model-argc-argv <n> model up to <n> command line arguments\n"
// NOLINTNEXTLINE(whitespace/line_length)
" --remove-function-body <f> remove the implementation of function <f> (may be repeated)\n"
HELP_REPLACE_CALLS
"\n"
"Other options:\n"
" --no-system-headers with --dump-c/--dump-cpp: generate C source expanding libc includes\n" // NOLINT(*)
Expand Down
5 changes: 4 additions & 1 deletion src/goto-instrument/goto_instrument_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
#include <goto-programs/goto_functions.h>
#include <goto-programs/remove_calls_no_body.h>
#include <goto-programs/remove_const_function_pointers.h>
#include <goto-programs/replace_calls.h>
#include <goto-programs/show_goto_functions.h>
#include <goto-programs/show_properties.h>

Expand Down Expand Up @@ -97,7 +98,9 @@ Author: Daniel Kroening, [email protected]
OPT_REMOVE_CALLS_NO_BODY \
OPT_REPLACE_FUNCTION_BODY \
OPT_GOTO_PROGRAM_STATS \
"(show-local-safe-pointers)(show-safe-dereferences)"
"(show-local-safe-pointers)(show-safe-dereferences)" \
OPT_REPLACE_CALLS \
// empty last line

// clang-format on

Expand Down
7 changes: 4 additions & 3 deletions src/goto-programs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SRC = adjust_float_expressions.cpp \
destructor.cpp \
elf_reader.cpp \
format_strings.cpp \
initialize_goto_model.cpp \
generate_function_bodies.cpp \
goto_asm.cpp \
goto_clean_expr.cpp \
goto_convert.cpp \
Expand All @@ -16,12 +16,13 @@ SRC = adjust_float_expressions.cpp \
goto_convert_side_effect.cpp \
goto_function.cpp \
goto_functions.cpp \
goto_inline.cpp \
goto_inline_class.cpp \
goto_inline.cpp \
goto_program.cpp \
goto_program_template.cpp \
goto_trace.cpp \
graphml_witness.cpp \
initialize_goto_model.cpp \
instrument_preconditions.cpp \
interpreter.cpp \
interpreter_evaluate.cpp \
Expand Down Expand Up @@ -50,7 +51,7 @@ SRC = adjust_float_expressions.cpp \
remove_unused_functions.cpp \
remove_vector.cpp \
remove_virtual_functions.cpp \
generate_function_bodies.cpp \
replace_calls.cpp \
resolve_inherited_component.cpp \
safety_checker.cpp \
set_properties.cpp \
Expand Down
Loading