Skip to content

Do not remove calls to functions without a body during inlining #1010

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 2 commits into from
Mar 1, 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
3 changes: 2 additions & 1 deletion regression/goto-instrument/inline_09/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--inline
--inline --remove-calls-no-body
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
Expand All @@ -9,4 +9,5 @@ main.c
^\s*a;$
no body.*[`]f
--
f\(\)
^warning: ignoring
9 changes: 9 additions & 0 deletions regression/goto-instrument/inline_16/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void func1();

int main()
{
int ret;

func1();
ret = func2();
}
12 changes: 12 additions & 0 deletions regression/goto-instrument/inline_16/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--inline
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
func1\(\)
ret.*=.*func2\(\)
no body for function.*func1
no body for function.*func2
--
^warning: ignoring
9 changes: 9 additions & 0 deletions regression/goto-instrument/inline_17/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void func1()
{
func2();
}

int main()
{
func1();
}
10 changes: 10 additions & 0 deletions regression/goto-instrument/inline_17/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--function-inline func1
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
func1\(\)
func2\(\)
--
^warning: ignoring
19 changes: 19 additions & 0 deletions regression/goto-instrument/remove-calls-no-body1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
void func1();

void func3()
{
}

void func4()
{
func1();
func2();
}

void main()
{
func1();
func2();
func3();
func4();
}
12 changes: 12 additions & 0 deletions regression/goto-instrument/remove-calls-no-body1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--remove-calls-no-body
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
func3\(\)
func4\(\)
--
func1\(\)
func2\(\)
^warning: ignoring
21 changes: 21 additions & 0 deletions regression/goto-instrument/remove-calls-no-body2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
int func1(int arg1, int arg2);

void func3()
{
}

void func4()
{
func1(567, 285);
func2();
}

void main()
{
int ret1;

ret1 = func1(567, 285);
func2();
func3();
func4();
}
15 changes: 15 additions & 0 deletions regression/goto-instrument/remove-calls-no-body2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CORE
main.c
--remove-calls-no-body
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
func3\(\)
func4\(\)
567;
285;
ret1.*=.*NONDET
--
func1\(.*\)
func2\(.*\)
^warning: ignoring
32 changes: 17 additions & 15 deletions src/goto-instrument/goto_instrument_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]

#include <goto-programs/class_hierarchy.h>
#include <goto-programs/goto_convert_functions.h>
#include <goto-programs/remove_calls_no_body.h>
#include <goto-programs/remove_function_pointers.h>
#include <goto-programs/remove_virtual_functions.h>
#include <goto-programs/remove_exceptions.h>
Expand Down Expand Up @@ -729,6 +730,10 @@ int goto_instrument_parse_optionst::doit()
status() << "Performing full inlining" << eom;
goto_inline(goto_model, get_message_handler());

status() << "Removing calls to functions without a body" << eom;
remove_calls_no_bodyt remove_calls_no_body;
remove_calls_no_body(goto_model.goto_functions);

status() << "Accelerating" << eom;
accelerate_functions(
goto_model, get_message_handler(), cmdline.isset("z3"));
Expand Down Expand Up @@ -992,7 +997,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
// now do full inlining, if requested
if(cmdline.isset("inline"))
{
do_indirect_call_and_rtti_removal();
do_indirect_call_and_rtti_removal(true);

if(cmdline.isset("show-custom-bitvector-analysis") ||
cmdline.isset("custom-bitvector-analysis"))
Expand All @@ -1003,7 +1008,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
}

status() << "Performing full inlining" << eom;
goto_inline(goto_model, get_message_handler());
goto_inline(goto_model, get_message_handler(), true);
}

if(cmdline.isset("show-custom-bitvector-analysis") ||
Expand Down Expand Up @@ -1111,27 +1116,23 @@ void goto_instrument_parse_optionst::instrument_goto_program()
if(cmdline.isset("partial-inline"))
{
do_indirect_call_and_rtti_removal();
do_partial_inlining();

status() << "Partial inlining" << eom;
goto_partial_inline(goto_model, ui_message_handler, 0, true);

goto_model.goto_functions.update();
goto_model.goto_functions.compute_loop_numbers();
}

// now do full inlining, if requested
if(cmdline.isset("inline"))
if(cmdline.isset("remove-calls-no-body"))
{
do_indirect_call_and_rtti_removal(/*force=*/true);
status() << "Removing calls to functions without a body" << eom;

if(cmdline.isset("show-custom-bitvector-analysis") ||
cmdline.isset("custom-bitvector-analysis"))
{
do_remove_returns();
thread_exit_instrumentation(goto_model);
mutex_init_instrumentation(goto_model);
}
remove_calls_no_bodyt remove_calls_no_body;
remove_calls_no_body(goto_model.goto_functions);

status() << "Performing full inlining" << eom;
goto_inline(goto_model, get_message_handler(), true);
goto_model.goto_functions.update();
goto_model.goto_functions.compute_loop_numbers();
}

if(cmdline.isset("constant-propagator"))
Expand Down Expand Up @@ -1560,6 +1561,7 @@ void goto_instrument_parse_optionst::help()
" --no-caching disable caching of intermediate results during transitive function inlining\n" // NOLINT(*)
" --log <file> log in json format which code segments were inlined, use with --function-inline\n" // NOLINT(*)
" --remove-function-pointers replace function pointers by case statement over function calls\n" // NOLINT(*)
HELP_REMOVE_CALLS_NO_BODY
HELP_REMOVE_CONST_FUNCTION_POINTERS
" --add-library add models of C library functions\n"
" --model-argc-argv <n> model up to <n> command line arguments\n"
Expand Down
4 changes: 3 additions & 1 deletion src/goto-instrument/goto_instrument_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Author: Daniel Kroening, [email protected]
#include <goto-programs/goto_functions.h>
#include <goto-programs/show_goto_functions.h>
#include <goto-programs/show_properties.h>
#include <goto-programs/remove_calls_no_body.h>
#include <goto-programs/remove_const_function_pointers.h>

#include <analyses/goto_check.h>
Expand Down Expand Up @@ -84,7 +85,8 @@ Author: Daniel Kroening, [email protected]
"(show-threaded)(list-calls-args)(print-path-lengths)" \
"(undefined-function-is-assume-false)" \
"(remove-function-body):"\
"(splice-call):"
"(splice-call):" \
OPT_REMOVE_CALLS_NO_BODY
// clang-format on

class goto_instrument_parse_optionst:
Expand Down
1 change: 1 addition & 0 deletions src/goto-programs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ SRC = basic_blocks.cpp \
read_goto_binary.cpp \
rebuild_goto_start_function.cpp \
remove_asm.cpp \
remove_calls_no_body.cpp \
remove_complex.cpp \
remove_const_function_pointers.cpp \
remove_exceptions.cpp \
Expand Down
61 changes: 7 additions & 54 deletions src/goto-programs/goto_inline_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,59 +380,6 @@ void goto_inlinet::insert_function_body(
dest.destructive_insert(target, tmp);
}

void goto_inlinet::insert_function_nobody(
goto_programt &dest,
const exprt &lhs,
goto_programt::targett target,
const symbol_exprt &function,
const exprt::operandst &arguments)
{
PRECONDITION(target->is_function_call());
PRECONDITION(!dest.empty());

const irep_idt identifier=function.get_identifier();

if(no_body_set.insert(identifier).second) // newly inserted
{
warning().source_location=function.find_source_location();
warning() << "no body for function `" << identifier << "'" << eom;
}

goto_programt tmp;

// evaluate function arguments -- they might have
// pointer dereferencing or the like
forall_expr(it, arguments)
{
goto_programt::targett t=tmp.add_instruction();
t->make_other(code_expressiont(*it));
t->source_location=target->source_location;
t->function=target->function;
}

// return value
if(lhs.is_not_nil())
{
side_effect_expr_nondett rhs(lhs.type());
rhs.add_source_location()=target->source_location;

code_assignt code(lhs, rhs);
code.add_source_location()=target->source_location;

goto_programt::targett t=tmp.add_instruction(ASSIGN);
t->source_location=target->source_location;
t->function=target->function;
t->code.swap(code);
}

// kill call
target->type=LOCATION;
target->code.clear();
target++;

dest.destructive_insert(target, tmp);
}

void goto_inlinet::expand_function_call(
goto_programt &dest,
const inline_mapt &inline_map,
Expand Down Expand Up @@ -551,7 +498,13 @@ void goto_inlinet::expand_function_call(
}
else // no body available
{
insert_function_nobody(dest, lhs, target, function, arguments);
const irep_idt identifier = function.get_identifier();

if(no_body_set.insert(identifier).second) // newly inserted
{
warning().source_location = function.find_source_location();
warning() << "no body for function `" << identifier << "'" << eom;
}
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/goto-programs/goto_inline_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ class goto_inlinet:public messaget
const symbol_exprt &function,
const exprt::operandst &arguments);

void insert_function_nobody(
goto_programt &dest,
const exprt &lhs,
goto_programt::targett target,
const symbol_exprt &function,
const exprt::operandst &arguments);

void replace_return(
goto_programt &body,
const exprt &lhs);
Expand Down
Loading