Skip to content

Commit 5875335

Browse files
committed
goto-instrument: Replace calls to undefined functions by assume(false)
Refactoring: moving print-undefined-functions to the new source file.
1 parent 50170f0 commit 5875335

File tree

6 files changed

+122
-7
lines changed

6 files changed

+122
-7
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* GOTO-INSTRUMENT: New option --list-calls-args
55
* GOTO-INSTRUMENT: New option --print-path-lenghts
66
* GOTO-ANALYZER: New option --unreachable-functions, --reachable-functions
7+
* GOTO-INSTRUMENT: New option --undefined-function-is-assume-false
78

89

910
5.7

src/goto-instrument/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ SRC = goto_instrument_parse_options.cpp rw_set.cpp \
2323
wmm/event_graph.cpp wmm/pair_collection.cpp \
2424
goto_instrument_main.cpp horn_encoding.cpp \
2525
thread_instrumentation.cpp skip_loops.cpp loop_utils.cpp \
26-
code_contracts.cpp cover.cpp model_argc_argv.cpp
26+
code_contracts.cpp cover.cpp model_argc_argv.cpp \
27+
undefined_functions.cpp
2728

2829
OBJ += ../ansi-c/ansi-c$(LIBEXT) \
2930
../cpp/cpp$(LIBEXT) \

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Author: Daniel Kroening, [email protected]
8989
#include "code_contracts.h"
9090
#include "unwind.h"
9191
#include "model_argc_argv.h"
92+
#include "undefined_functions.h"
9293

9394
/*******************************************************************\
9495
@@ -628,11 +629,7 @@ int goto_instrument_parse_optionst::doit()
628629
if(cmdline.isset("list-undefined-functions"))
629630
{
630631
const namespacet ns(symbol_table);
631-
632-
Forall_goto_functions(it, goto_functions)
633-
if(!ns.lookup(it->first).is_macro &&
634-
!it->second.body_available())
635-
std::cout << it->first << std::endl;
632+
list_undefined_functions(goto_functions, ns, std::cout);
636633
return 0;
637634
}
638635

@@ -769,6 +766,13 @@ int goto_instrument_parse_optionst::doit()
769766
remove_unused_functions(goto_functions, get_message_handler());
770767
}
771768

769+
if(cmdline.isset("undefined-function-is-assume-false"))
770+
{
771+
do_indirect_call_and_rtti_removal();
772+
773+
undefined_function_abort_path(goto_functions);
774+
}
775+
772776
// write new binary?
773777
if(cmdline.args.size()==2)
774778
{
@@ -1549,6 +1553,8 @@ void goto_instrument_parse_optionst::help()
15491553
" --nondet-static add nondeterministic initialization of variables with static lifetime\n" // NOLINT(*)
15501554
" --check-invariant function instruments invariant checking function\n"
15511555
" --remove-pointers converts pointer arithmetic to base+offset expressions\n" // NOLINT(*)
1556+
" --undefined-function-is-assume-false\n"
1557+
" convert each call to an undefined function to assume(false)\n"
15521558
"\n"
15531559
"Loop transformations:\n"
15541560
" --k-induction <k> check loops with k-induction\n"

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ Author: Daniel Kroening, [email protected]
6969
"(list-symbols)(list-undefined-functions)" \
7070
"(z3)(add-library)(show-dependence-graph)" \
7171
"(horn)(skip-loops):(apply-code-contracts)(model-argc-argv):" \
72-
"(show-threaded)(list-calls-args)(print-path-lengths)"
72+
"(show-threaded)(list-calls-args)(print-path-lengths)" \
73+
"(undefined-function-is-assume-false)"
7374

7475
class goto_instrument_parse_optionst:
7576
public parse_options_baset,
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*******************************************************************\
2+
3+
Module: Handling of functions without body
4+
5+
Author: Michael Tautschnig
6+
7+
Date: July 2016
8+
9+
\*******************************************************************/
10+
11+
#include <ostream>
12+
13+
#include <goto-programs/goto_functions.h>
14+
15+
#include "undefined_functions.h"
16+
17+
/*******************************************************************\
18+
19+
Function: list_undefined_functions
20+
21+
Inputs:
22+
23+
Outputs:
24+
25+
Purpose:
26+
27+
\*******************************************************************/
28+
29+
void list_undefined_functions(
30+
const goto_functionst &goto_functions,
31+
const namespacet &ns,
32+
std::ostream &os)
33+
{
34+
forall_goto_functions(it, goto_functions)
35+
if(!ns.lookup(it->first).is_macro &&
36+
!it->second.body_available())
37+
os << it->first << std::endl;
38+
}
39+
40+
/*******************************************************************\
41+
42+
Function: undefined_function_abort_path
43+
44+
Inputs:
45+
46+
Outputs:
47+
48+
Purpose:
49+
50+
\*******************************************************************/
51+
52+
void undefined_function_abort_path(goto_functionst &goto_functions)
53+
{
54+
Forall_goto_functions(it, goto_functions)
55+
Forall_goto_program_instructions(iit, it->second.body)
56+
{
57+
goto_programt::instructiont &ins=*iit;
58+
59+
if(!ins.is_function_call())
60+
continue;
61+
62+
const code_function_callt &call=to_code_function_call(ins.code);
63+
64+
if(call.function().id()!=ID_symbol)
65+
continue;
66+
67+
const irep_idt &function=
68+
to_symbol_expr(call.function()).get_identifier();
69+
70+
goto_functionst::function_mapt::const_iterator entry=
71+
goto_functions.function_map.find(function);
72+
assert(entry!=goto_functions.function_map.end());
73+
74+
if(entry->second.body_available())
75+
continue;
76+
77+
ins.make_assumption(false_exprt());
78+
ins.source_location.set_comment(
79+
"`"+id2string(function)+"' is undefined");
80+
}
81+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************\
2+
3+
Module: Handling of functions without body
4+
5+
Author: Michael Tautschnig
6+
7+
Date: July 2016
8+
9+
\*******************************************************************/
10+
11+
#ifndef CPROVER_UNDEFINED_FUNCTIONS_H
12+
#define CPROVER_UNDEFINED_FUNCTIONS_H
13+
14+
#include <iosfwd>
15+
16+
class goto_functionst;
17+
18+
void list_undefined_functions(
19+
const goto_functionst &goto_functions,
20+
const namespacet &ns,
21+
std::ostream &os);
22+
23+
void undefined_function_abort_path(goto_functionst &goto_functions);
24+
25+
#endif

0 commit comments

Comments
 (0)