Skip to content

Commit 9d874aa

Browse files
Add option to generate function body to goto-instrument
1 parent 96bf623 commit 9d874aa

File tree

15 files changed

+455
-3
lines changed

15 files changed

+455
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
void do_not_call_this(void);
2+
3+
int main(void)
4+
{
5+
do_not_call_this();
6+
}
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-function-body do_not_call_this --replace-function-body-options assert-false
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[do_not_call_this.assertion.1\] assertion FALSE: FAILURE$
7+
--
8+
^warning: ignoring
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
3+
void will_not_return(void);
4+
5+
int main(void)
6+
{
7+
will_not_return();
8+
assert(0);
9+
}
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-function-body will_not_return --replace-function-body-options assume-false
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
3+
int global = 10;
4+
const int constant_global = 10;
5+
6+
void touches_globals(void);
7+
8+
int main(void)
9+
{
10+
touches_globals();
11+
assert(global == 10);
12+
assert(constant_global == 10);
13+
}
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-function-body touches_globals --replace-function-body-options 'havoc,globals:(?!__).*'
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
^\[main.assertion.1\] assertion global == 10: FAILURE$
8+
^\[main.assertion.2\] assertion constant_global == 10: SUCCESS$
9+
--
10+
^warning: ignoring
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
3+
void touches_parameter(int *param, const int *const_param);
4+
5+
int main(void)
6+
{
7+
int parameter = 10;
8+
int constant_parameter = 10;
9+
touches_parameter(&parameter, &constant_parameter);
10+
assert(parameter == 10);
11+
assert(constant_parameter == 10);
12+
}
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-function-body touches_parameter --replace-function-body-options havoc,params
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
^\[main.assertion.1\] assertion parameter == 10: FAILURE$
8+
^\[main.assertion.2\] assertion constant_parameter == 10: SUCCESS$
9+
--
10+
^warning: ignoring
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <assert.h>
2+
3+
int this_returns_ten(void)
4+
{
5+
return 10;
6+
}
7+
8+
int main(void)
9+
{
10+
assert(this_returns_ten() == 10);
11+
}
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-function-body this_returns_ten --replace-function-body-options nondet-return
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring

src/goto-instrument/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ SRC = accelerate/accelerate.cpp \
6161
undefined_functions.cpp \
6262
uninitialized.cpp \
6363
unwind.cpp \
64+
replace_function_bodies.cpp \
6465
wmm/abstract_event.cpp \
6566
wmm/cycle_collection.cpp \
6667
wmm/data_dp.cpp \

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Author: Daniel Kroening, kroening@kroening.com
9999
#include "undefined_functions.h"
100100
#include "remove_function.h"
101101
#include "splice_call.h"
102+
#include "replace_function_bodies.h"
102103

103104
void goto_instrument_parse_optionst::eval_verbosity()
104105
{
@@ -1447,6 +1448,16 @@ void goto_instrument_parse_optionst::instrument_goto_program()
14471448
throw 0;
14481449
}
14491450

1451+
if(cmdline.isset("replace-function-body"))
1452+
{
1453+
status() << "Replacing function bodies" << eom;
1454+
replace_function_bodies(
1455+
goto_model.goto_functions,
1456+
goto_model.symbol_table,
1457+
std::regex(cmdline.get_value("replace-function-body")),
1458+
cmdline.get_value("replace-function-body-options"));
1459+
}
1460+
14501461
// recalculate numbers, etc.
14511462
goto_model.goto_functions.update();
14521463
}
@@ -1522,8 +1533,13 @@ void goto_instrument_parse_optionst::help()
15221533
" --remove-pointers converts pointer arithmetic to base+offset expressions\n" // NOLINT(*)
15231534
" --splice-call caller,callee prepends a call to callee in the body of caller\n" // NOLINT(*)
15241535
// NOLINTNEXTLINE(whitespace/line_length)
1525-
" --undefined-function-is-assume-false\n" // NOLINTNEXTLINE(whitespace/line_length)
1526-
" convert each call to an undefined function to assume(false)\n"
1536+
" --undefined-function-is-assume-false\n"
1537+
// NOLINTNEXTLINE(whitespace/line_length)
1538+
" --replace-function-body <regex> Replace bodies of function matching regex\n"
1539+
// NOLINTNEXTLINE(whitespace/line_length)
1540+
" --replace-function-body-options <option> One of assert-false, assume-false, nondet-return and\n"
1541+
// NOLINTNEXTLINE(whitespace/line_length)
1542+
" havoc[,params][,globals:<regex>]"
15271543
"\n"
15281544
"Loop transformations:\n"
15291545
" --k-induction <k> check loops with k-induction\n"

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ Author: Daniel Kroening, kroening@kroening.com
8484
"(show-threaded)(list-calls-args)(print-path-lengths)" \
8585
"(undefined-function-is-assume-false)" \
8686
"(remove-function-body):"\
87-
"(splice-call):"
87+
"(splice-call):" \
88+
"(replace-function-body):" \
89+
"(replace-function-body-options):"
90+
8891
// clang-format on
8992

9093
class goto_instrument_parse_optionst:

0 commit comments

Comments
 (0)