Skip to content

Support labels in unwindset/function-pointer-restrictions #6508

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 3 commits into from
Dec 8, 2021
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
7 changes: 5 additions & 2 deletions doc/architectural/restrict-function-pointer.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ function where function pointers are being called, to this pattern:
```
<function-name>.function_pointer_call.<N>
```

where `N` is referring to which function call it is - so the first call to a
function pointer in a function will have `N=1`, the 5th `N=5` etc.
function pointer in a function will have `N=1`, the 5th `N=5` etc, or
```
<function-name>.<label>
```
when the function call is labelled.

We can call `goto-instrument --restrict-function-pointer
call.function_pointer_call.1/f,g in.gb out.gb`. This can be read as
Expand Down
8 changes: 8 additions & 0 deletions regression/cbmc/unwindset1/label.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--unwindset main.for_loop:2,main.1:6
^VERIFICATION FAILED$
^EXIT=10$
^SIGNAL=0$
--
^warning: ignoring
10 changes: 10 additions & 0 deletions regression/cbmc/unwindset1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
int main()
{
int x;
for_loop:
for(int i = 0; i < x; ++i)
--x;
for(int j = 0; j < 5; ++j)
++x;
__CPROVER_assert(0, "can be reached");
}
10 changes: 10 additions & 0 deletions regression/cbmc/unwindset1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--unwindset main.0:2,main.2:2
^Invalid User Input$
^Option: unwindset$
^Reason: invalid loop identifier main\.2$
^EXIT=1$
^SIGNAL=0$
--
^warning: ignoring
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <assert.h>

typedef int (*fptr_t)(int);

void use_f(fptr_t fptr)
{
labelled_call:
assert(fptr(10) == 11);
}

int f(int x)
{
return x + 1;
}

int g(int x)
{
return x;
}

int main(void)
{
int one = 1;

// We take the address of f and g. In this case remove_function_pointers()
// would create a case distinction involving both f and g in the function
// use_f() above.
use_f(one ? f : g);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
test.c
--restrict-function-pointer use_f.labelled_call/f
\[use_f\.assertion\.1\] line \d+ assertion fptr\(10\) == 11: SUCCESS
^EXIT=0$
^SIGNAL=0$
--
--
This test checks that the function f is called for the first function pointer
call in function use_f when using the label to refer to the call site.
4 changes: 3 additions & 1 deletion src/goto-checker/multi_path_symex_only_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ multi_path_symex_only_checkert::multi_path_symex_only_checkert(
goto_model(goto_model),
ns(goto_model.get_symbol_table(), symex_symbol_table),
equation(ui_message_handler),
unwindset(goto_model),
symex(
ui_message_handler,
goto_model.get_symbol_table(),
equation,
options,
path_storage,
guard_manager)
guard_manager,
unwindset)
{
setup_symex(symex, ns, options, ui_message_handler);
}
Expand Down
3 changes: 3 additions & 0 deletions src/goto-checker/multi_path_symex_only_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Author: Daniel Kroening, Peter Schrammel

#include <goto-symex/path_storage.h>

#include <goto-instrument/unwindset.h>

#include "symex_bmc.h"

class multi_path_symex_only_checkert : public incremental_goto_checkert
Expand All @@ -35,6 +37,7 @@ class multi_path_symex_only_checkert : public incremental_goto_checkert
symex_target_equationt equation;
guard_managert guard_manager;
path_fifot path_storage; // should go away
unwindsett unwindset;
symex_bmct symex;

/// Generates the equation by running goto-symex
Expand Down
2 changes: 2 additions & 0 deletions src/goto-checker/single_loop_incremental_symex_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ single_loop_incremental_symex_checkert::single_loop_incremental_symex_checkert(
goto_model(goto_model),
ns(goto_model.get_symbol_table(), symex_symbol_table),
equation(ui_message_handler),
unwindset(goto_model),
symex(
ui_message_handler,
goto_model.get_symbol_table(),
equation,
options,
path_storage,
guard_manager,
unwindset,
ui_message_handler.get_ui()),
property_decider(options, ui_message_handler, equation, ns)
{
Expand Down
3 changes: 3 additions & 0 deletions src/goto-checker/single_loop_incremental_symex_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Author: Daniel Kroening, Peter Schrammel

#include <goto-symex/path_storage.h>

#include <goto-instrument/unwindset.h>

#include "goto_symex_property_decider.h"
#include "goto_trace_provider.h"
#include "incremental_goto_checker.h"
Expand Down Expand Up @@ -57,6 +59,7 @@ class single_loop_incremental_symex_checkert : public incremental_goto_checkert,
symex_target_equationt equation;
path_fifot path_storage; // should go away
guard_managert guard_manager;
unwindsett unwindset;
symex_bmc_incremental_one_loopt symex;
bool initial_equation_generated = false;
bool full_equation_generated = false;
Expand Down
9 changes: 6 additions & 3 deletions src/goto-checker/single_path_symex_only_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ single_path_symex_only_checkert::single_path_symex_only_checkert(
goto_model(goto_model),
ns(goto_model.get_symbol_table(), symex_symbol_table),
worklist(get_path_strategy(options.get_option("exploration-strategy"))),
symex_runtime(0)
symex_runtime(0),
unwindset(goto_model)
{
}

Expand Down Expand Up @@ -70,7 +71,8 @@ void single_path_symex_only_checkert::initialize_worklist()
equation,
options,
*worklist,
guard_manager);
guard_manager,
unwindset);
setup_symex(symex);

symex.initialize_path_storage_from_entry_point_of(
Expand All @@ -95,7 +97,8 @@ bool single_path_symex_only_checkert::resume_path(path_storaget::patht &path)
path.equation,
options,
*worklist,
guard_manager);
guard_manager,
unwindset);
setup_symex(symex);

symex.resume_symex_from_saved_state(
Expand Down
3 changes: 3 additions & 0 deletions src/goto-checker/single_path_symex_only_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Author: Daniel Kroening, Peter Schrammel

#include <goto-symex/path_storage.h>

#include <goto-instrument/unwindset.h>

#include <chrono>

class symex_bmct;
Expand All @@ -40,6 +42,7 @@ class single_path_symex_only_checkert : public incremental_goto_checkert
guard_managert guard_manager;
std::unique_ptr<path_storaget> worklist;
std::chrono::duration<double> symex_runtime;
unwindsett unwindset;

void equation_output(
const symex_bmct &symex,
Expand Down
6 changes: 5 additions & 1 deletion src/goto-checker/symex_bmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ Author: Daniel Kroening, [email protected]
#include <util/simplify_expr.h>
#include <util/source_location.h>

#include <goto-instrument/unwindset.h>

symex_bmct::symex_bmct(
message_handlert &mh,
const symbol_tablet &outer_symbol_table,
symex_target_equationt &_target,
const optionst &options,
path_storaget &path_storage,
guard_managert &guard_manager)
guard_managert &guard_manager,
unwindsett &unwindset)
: goto_symext(
mh,
outer_symbol_table,
Expand All @@ -33,6 +36,7 @@ symex_bmct::symex_bmct(
record_coverage(!options.get_option("symex-coverage-report").empty()),
havoc_bodyless_functions(
options.get_bool_option("havoc-undefined-functions")),
unwindset(unwindset),
symex_coverage(ns)
{
}
Expand Down
9 changes: 5 additions & 4 deletions src/goto-checker/symex_bmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Author: Daniel Kroening, [email protected]

#include <goto-symex/goto_symex.h>

#include <goto-instrument/unwindset.h>

#include "symex_coverage.h"

class unwindsett;

class symex_bmct : public goto_symext
{
public:
Expand All @@ -29,7 +29,8 @@ class symex_bmct : public goto_symext
symex_target_equationt &_target,
const optionst &options,
path_storaget &path_storage,
guard_managert &guard_manager);
guard_managert &guard_manager,
unwindsett &unwindset);

// To show progress
source_locationt last_source_location;
Expand Down Expand Up @@ -81,7 +82,7 @@ class symex_bmct : public goto_symext
const bool record_coverage;
const bool havoc_bodyless_functions;

unwindsett unwindset;
unwindsett &unwindset;

protected:
/// Callbacks that may provide an unwind/do-not-unwind decision for a loop
Expand Down
6 changes: 5 additions & 1 deletion src/goto-checker/symex_bmc_incremental_one_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ Author: Peter Schrammel, Daniel Kroening, [email protected]

#include <util/structured_data.h>

#include <goto-instrument/unwindset.h>

symex_bmc_incremental_one_loopt::symex_bmc_incremental_one_loopt(
message_handlert &message_handler,
const symbol_tablet &outer_symbol_table,
symex_target_equationt &target,
const optionst &options,
path_storaget &path_storage,
guard_managert &guard_manager,
unwindsett &unwindset,
ui_message_handlert::uit output_ui)
: symex_bmct(
message_handler,
outer_symbol_table,
target,
options,
path_storage,
guard_manager),
guard_manager,
unwindset),
incr_loop_id(options.get_option("incremental-loop")),
incr_max_unwind(
options.is_set("unwind-max") ? options.get_signed_int_option("unwind-max")
Expand Down
1 change: 1 addition & 0 deletions src/goto-checker/symex_bmc_incremental_one_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class symex_bmc_incremental_one_loopt : public symex_bmct
const optionst &,
path_storaget &,
guard_managert &,
unwindsett &,
ui_message_handlert::uit output_ui);

/// Return true if symex can be resumed
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/goto_instrument_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ int goto_instrument_parse_optionst::doit()

if(unwind_given || unwindset_given || unwindset_file_given)
{
unwindsett unwindset;
unwindsett unwindset{goto_model};

if(unwind_given)
unwindset.parse_unwind(cmdline.get_value("unwind"));
Expand Down
Loading