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;

src/goto-checker/single_path_symex_only_checker.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ single_path_symex_only_checkert::single_path_symex_only_checkert(
3030
goto_model(goto_model),
3131
ns(goto_model.get_symbol_table(), symex_symbol_table),
3232
worklist(get_path_strategy(options.get_option("exploration-strategy"))),
33-
symex_runtime(0)
33+
symex_runtime(0),
34+
unwindset(goto_model)
3435
{
3536
}
3637

@@ -70,7 +71,8 @@ void single_path_symex_only_checkert::initialize_worklist()
7071
equation,
7172
options,
7273
*worklist,
73-
guard_manager);
74+
guard_manager,
75+
unwindset);
7476
setup_symex(symex);
7577

7678
symex.initialize_path_storage_from_entry_point_of(
@@ -95,7 +97,8 @@ bool single_path_symex_only_checkert::resume_path(path_storaget::patht &path)
9597
path.equation,
9698
options,
9799
*worklist,
98-
guard_manager);
100+
guard_manager,
101+
unwindset);
99102
setup_symex(symex);
100103

101104
symex.resume_symex_from_saved_state(

src/goto-checker/single_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 <chrono>
2022

2123
class symex_bmct;
@@ -40,6 +42,7 @@ class single_path_symex_only_checkert : public incremental_goto_checkert
4042
guard_managert guard_manager;
4143
std::unique_ptr<path_storaget> worklist;
4244
std::chrono::duration<double> symex_runtime;
45+
unwindsett unwindset;
4346

4447
void equation_output(
4548
const symex_bmct &symex,

src/goto-checker/symex_bmc.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/simplify_expr.h>
1717
#include <util/source_location.h>
1818

19+
#include <goto-instrument/unwindset.h>
20+
1921
symex_bmct::symex_bmct(
2022
message_handlert &mh,
2123
const symbol_tablet &outer_symbol_table,
2224
symex_target_equationt &_target,
2325
const optionst &options,
2426
path_storaget &path_storage,
25-
guard_managert &guard_manager)
27+
guard_managert &guard_manager,
28+
unwindsett &unwindset)
2629
: goto_symext(
2730
mh,
2831
outer_symbol_table,
@@ -33,6 +36,7 @@ symex_bmct::symex_bmct(
3336
record_coverage(!options.get_option("symex-coverage-report").empty()),
3437
havoc_bodyless_functions(
3538
options.get_bool_option("havoc-undefined-functions")),
39+
unwindset(unwindset),
3640
symex_coverage(ns)
3741
{
3842
}

src/goto-checker/symex_bmc.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Author: Daniel Kroening, [email protected]
1616

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

19-
#include <goto-instrument/unwindset.h>
20-
2119
#include "symex_coverage.h"
2220

21+
class unwindsett;
22+
2323
class symex_bmct : public goto_symext
2424
{
2525
public:
@@ -29,7 +29,8 @@ class symex_bmct : public goto_symext
2929
symex_target_equationt &_target,
3030
const optionst &options,
3131
path_storaget &path_storage,
32-
guard_managert &guard_manager);
32+
guard_managert &guard_manager,
33+
unwindsett &unwindset);
3334

3435
// To show progress
3536
source_locationt last_source_location;
@@ -81,7 +82,7 @@ class symex_bmct : public goto_symext
8182
const bool record_coverage;
8283
const bool havoc_bodyless_functions;
8384

84-
unwindsett unwindset;
85+
unwindsett &unwindset;
8586

8687
protected:
8788
/// Callbacks that may provide an unwind/do-not-unwind decision for a loop

src/goto-checker/symex_bmc_incremental_one_loop.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@ Author: Peter Schrammel, Daniel Kroening, [email protected]
1212

1313
#include <util/structured_data.h>
1414

15+
#include <goto-instrument/unwindset.h>
16+
1517
symex_bmc_incremental_one_loopt::symex_bmc_incremental_one_loopt(
1618
message_handlert &message_handler,
1719
const symbol_tablet &outer_symbol_table,
1820
symex_target_equationt &target,
1921
const optionst &options,
2022
path_storaget &path_storage,
2123
guard_managert &guard_manager,
24+
unwindsett &unwindset,
2225
ui_message_handlert::uit output_ui)
2326
: symex_bmct(
2427
message_handler,
2528
outer_symbol_table,
2629
target,
2730
options,
2831
path_storage,
29-
guard_manager),
32+
guard_manager,
33+
unwindset),
3034
incr_loop_id(options.get_option("incremental-loop")),
3135
incr_max_unwind(
3236
options.is_set("unwind-max") ? options.get_signed_int_option("unwind-max")

src/goto-checker/symex_bmc_incremental_one_loop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class symex_bmc_incremental_one_loopt : public symex_bmct
2222
const optionst &,
2323
path_storaget &,
2424
guard_managert &,
25+
unwindsett &,
2526
ui_message_handlert::uit output_ui);
2627

2728
/// Return true if symex can be resumed

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ int goto_instrument_parse_optionst::doit()
165165

166166
if(unwind_given || unwindset_given || unwindset_file_given)
167167
{
168-
unwindsett unwindset;
168+
unwindsett unwindset{goto_model};
169169

170170
if(unwind_given)
171171
unwindset.parse_unwind(cmdline.get_value("unwind"));

0 commit comments

Comments
 (0)