Skip to content

Commit e3719e3

Browse files
authored
Merge pull request #6508 from tautschnig/refer-by-label
Support labels in unwindset/function-pointer-restrictions
2 parents 7cc3027 + 771a153 commit e3719e3

23 files changed

+288
-37
lines changed

doc/architectural/restrict-function-pointer.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ function where function pointers are being called, to this pattern:
7373
```
7474
<function-name>.function_pointer_call.<N>
7575
```
76-
7776
where `N` is referring to which function call it is - so the first call to a
78-
function pointer in a function will have `N=1`, the 5th `N=5` etc.
77+
function pointer in a function will have `N=1`, the 5th `N=5` etc, or
78+
```
79+
<function-name>.<label>
80+
```
81+
when the function call is labelled.
7982

8083
We can call `goto-instrument --restrict-function-pointer
8184
call.function_pointer_call.1/f,g in.gb out.gb`. This can be read as

regression/cbmc/unwindset1/label.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwindset main.for_loop:2,main.1:6
4+
^VERIFICATION FAILED$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

regression/cbmc/unwindset1/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int main()
2+
{
3+
int x;
4+
for_loop:
5+
for(int i = 0; i < x; ++i)
6+
--x;
7+
for(int j = 0; j < 5; ++j)
8+
++x;
9+
__CPROVER_assert(0, "can be reached");
10+
}

regression/cbmc/unwindset1/test.desc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--unwindset main.0:2,main.2:2
4+
^Invalid User Input$
5+
^Option: unwindset$
6+
^Reason: invalid loop identifier main\.2$
7+
^EXIT=1$
8+
^SIGNAL=0$
9+
--
10+
^warning: ignoring
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <assert.h>
2+
3+
typedef int (*fptr_t)(int);
4+
5+
void use_f(fptr_t fptr)
6+
{
7+
labelled_call:
8+
assert(fptr(10) == 11);
9+
}
10+
11+
int f(int x)
12+
{
13+
return x + 1;
14+
}
15+
16+
int g(int x)
17+
{
18+
return x;
19+
}
20+
21+
int main(void)
22+
{
23+
int one = 1;
24+
25+
// We take the address of f and g. In this case remove_function_pointers()
26+
// would create a case distinction involving both f and g in the function
27+
// use_f() above.
28+
use_f(one ? f : g);
29+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
test.c
3+
--restrict-function-pointer use_f.labelled_call/f
4+
\[use_f\.assertion\.1\] line \d+ assertion fptr\(10\) == 11: SUCCESS
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
This test checks that the function f is called for the first function pointer
10+
call in function use_f when using the label to refer to the call site.

src/goto-checker/multi_path_symex_only_checker.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ multi_path_symex_only_checkert::multi_path_symex_only_checkert(
2828
goto_model(goto_model),
2929
ns(goto_model.get_symbol_table(), symex_symbol_table),
3030
equation(ui_message_handler),
31+
unwindset(goto_model),
3132
symex(
3233
ui_message_handler,
3334
goto_model.get_symbol_table(),
3435
equation,
3536
options,
3637
path_storage,
37-
guard_manager)
38+
guard_manager,
39+
unwindset)
3840
{
3941
setup_symex(symex, ns, options, ui_message_handler);
4042
}

src/goto-checker/multi_path_symex_only_checker.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Author: Daniel Kroening, Peter Schrammel
1616

1717
#include <goto-symex/path_storage.h>
1818

19+
#include <goto-instrument/unwindset.h>
20+
1921
#include "symex_bmc.h"
2022

2123
class multi_path_symex_only_checkert : public incremental_goto_checkert
@@ -35,6 +37,7 @@ class multi_path_symex_only_checkert : public incremental_goto_checkert
3537
symex_target_equationt equation;
3638
guard_managert guard_manager;
3739
path_fifot path_storage; // should go away
40+
unwindsett unwindset;
3841
symex_bmct symex;
3942

4043
/// Generates the equation by running goto-symex

src/goto-checker/single_loop_incremental_symex_checker.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ single_loop_incremental_symex_checkert::single_loop_incremental_symex_checkert(
3030
goto_model(goto_model),
3131
ns(goto_model.get_symbol_table(), symex_symbol_table),
3232
equation(ui_message_handler),
33+
unwindset(goto_model),
3334
symex(
3435
ui_message_handler,
3536
goto_model.get_symbol_table(),
3637
equation,
3738
options,
3839
path_storage,
3940
guard_manager,
41+
unwindset,
4042
ui_message_handler.get_ui()),
4143
property_decider(options, ui_message_handler, equation, ns)
4244
{

src/goto-checker/single_loop_incremental_symex_checker.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Author: Daniel Kroening, Peter Schrammel
1616

1717
#include <goto-symex/path_storage.h>
1818

19+
#include <goto-instrument/unwindset.h>
20+
1921
#include "goto_symex_property_decider.h"
2022
#include "goto_trace_provider.h"
2123
#include "incremental_goto_checker.h"
@@ -57,6 +59,7 @@ class single_loop_incremental_symex_checkert : public incremental_goto_checkert,
5759
symex_target_equationt equation;
5860
path_fifot path_storage; // should go away
5961
guard_managert guard_manager;
62+
unwindsett unwindset;
6063
symex_bmc_incremental_one_loopt symex;
6164
bool initial_equation_generated = false;
6265
bool full_equation_generated = false;

0 commit comments

Comments
 (0)