Skip to content

Commit e209fce

Browse files
Introduce goto checker interfaces
goto_checkert: returns a trace or 'done' goto_verifiert: uses goto_checkert to check a set of properties property utilities
1 parent 49ac569 commit e209fce

7 files changed

+324
-1
lines changed

src/goto-checker/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
SRC = bmc_util.cpp \
1+
SRC = incremental_goto_checker.cpp \
2+
goto_verifier.cpp \
3+
properties.cpp \
24
solver_factory.cpp \
35
symex_coverage.cpp \
46
symex_bmc.cpp \

src/goto-checker/goto_verifier.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*******************************************************************\
2+
3+
Module: Goto Verifier Interface
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Goto Verifier Interface
11+
12+
#include "goto_verifier.h"
13+
14+
goto_verifiert::goto_verifiert(
15+
const optionst &_options,
16+
ui_message_handlert &ui_message_handler)
17+
: options(_options),
18+
ui_message_handler(ui_message_handler),
19+
log(ui_message_handler)
20+
{
21+
}

src/goto-checker/goto_verifier.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*******************************************************************\
2+
3+
Module: Goto Verifier Interface
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Goto Verifier Interface
11+
12+
#ifndef CPROVER_GOTO_CHECKER_GOTO_VERIFIER_H
13+
#define CPROVER_GOTO_CHECKER_GOTO_VERIFIER_H
14+
15+
#include <util/optional.h>
16+
#include <util/options.h>
17+
#include <util/ui_message.h>
18+
19+
#include "properties.h"
20+
21+
/// An implementation of `goto_verifiert` checks all properties in
22+
/// a goto model. It typically uses, but doesn't have to use, a
23+
/// `goto_checkert` to iteratively determine the verification result
24+
/// of each property.
25+
class goto_verifiert
26+
{
27+
public:
28+
/// Check whether all properties hold.
29+
/// \return PASS if all properties are PASS,
30+
/// FAIL if at least one property is FAIL and no property is ERROR,
31+
/// UNKNOWN if no property is FAIL or ERROR and
32+
/// at least one property is UNKNOWN,
33+
/// ERROR if at least one property is error.
34+
virtual resultt operator()() = 0;
35+
36+
/// Report results
37+
virtual void report() = 0;
38+
39+
/// Returns the properties
40+
const propertiest &get_properties()
41+
{
42+
return properties;
43+
}
44+
45+
protected:
46+
goto_verifiert(const optionst &, ui_message_handlert &);
47+
48+
const optionst &options;
49+
ui_message_handlert &ui_message_handler;
50+
messaget log;
51+
propertiest properties;
52+
};
53+
54+
#endif // CPROVER_GOTO_CHECKER_GOTO_VERIFIER_H
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*******************************************************************\
2+
3+
Module: Goto Checker Interface
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Goto Checker Interface
11+
12+
#include "incremental_goto_checker.h"
13+
14+
incremental_goto_checkert::incremental_goto_checkert(
15+
const optionst &options,
16+
ui_message_handlert &ui_message_handler)
17+
: options(options),
18+
ui_message_handler(ui_message_handler),
19+
log(ui_message_handler)
20+
{
21+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*******************************************************************\
2+
3+
Module: Incremental Goto Checker Interface
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Goto Checker Interface
11+
12+
#ifndef CPROVER_GOTO_CHECKER_INCREMENTAL_GOTO_CHECKER_H
13+
#define CPROVER_GOTO_CHECKER_INCREMENTAL_GOTO_CHECKER_H
14+
15+
#include <util/ui_message.h>
16+
17+
#include "properties.h"
18+
19+
class goto_tracet;
20+
class optionst;
21+
22+
/// An implementation of `incremental_goto_checkert` provides functionality for
23+
/// checking a set of properties and returning counterexamples
24+
/// one by one to the caller.
25+
/// An implementation of `incremental_goto_checkert` is responsible for
26+
/// maintaining the state of the analysis that it performs (e.g. goto-symex,
27+
/// solver, etc).
28+
/// An implementation of `incremental_goto_checkert` is not responsible for
29+
/// maintaining outcomes (e.g. property results, counterexamples, etc).
30+
/// However, an implementation may restrict the sets of properties it is asked
31+
/// to check on repeated invocations of its operator (e.g. only sequences of
32+
/// subsets of properties) to optimize the incremental algorithm it uses.
33+
class incremental_goto_checkert
34+
{
35+
public:
36+
enum class statust
37+
{
38+
/// The goto checker may be able to find another FAILed property
39+
/// if operator() is called again.
40+
FOUND_FAIL,
41+
/// The goto checker has returned all results for the given set
42+
/// of properties.
43+
DONE
44+
};
45+
46+
/// Check whether the given properties with status NOT_CHECKED, UNKNOWN or
47+
/// properties newly discovered by `goto_checkert` hold.
48+
/// \param [out] properties: Properties updated to whether their results
49+
/// have been determined. Newly discovered properties are added.
50+
/// \return whether the goto checker found a violated property (FOUND_FAIL) or
51+
/// whether it is DONE with the given properties.
52+
/// After returning DONE, another call to operator() with the same
53+
/// properties will return DONE and leave the properties' results unchanged.
54+
/// If there is a property with status FAIL then its counterexample
55+
/// can be retrieved by calling `build_error_trace` before any
56+
/// subsequent call to operator().
57+
/// `goto_checkert` derivatives shall be implemented in a way such
58+
/// that repeated calls to operator() shall return when the next FAILed
59+
/// property has been found until eventually it does not find any
60+
/// failing properties any more.
61+
virtual statust operator()(propertiest &properties) = 0;
62+
63+
/// Builds and returns the counterexample
64+
virtual goto_tracet build_error_trace() const = 0;
65+
66+
protected:
67+
incremental_goto_checkert(const optionst &, ui_message_handlert &);
68+
69+
const optionst &options;
70+
ui_message_handlert &ui_message_handler;
71+
messaget log;
72+
};
73+
74+
#endif // CPROVER_GOTO_CHECKER_INCREMENTAL_GOTO_CHECKER_H

src/goto-checker/properties.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*******************************************************************\
2+
3+
Module: Properties
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Properties
11+
12+
#include "properties.h"
13+
14+
#include <util/invariant.h>
15+
16+
std::string as_string(resultt result)
17+
{
18+
switch(result)
19+
{
20+
case resultt::UNKNOWN:
21+
return "UNKNOWN";
22+
case resultt::PASS:
23+
return "PASS";
24+
case resultt::FAIL:
25+
return "FAIL";
26+
case resultt::ERROR:
27+
return "ERROR";
28+
}
29+
30+
UNREACHABLE;
31+
}
32+
33+
std::string as_string(property_resultt result)
34+
{
35+
switch(result)
36+
{
37+
case property_resultt::NOT_CHECKED:
38+
return "NOT CHECKED";
39+
case property_resultt::UNKNOWN:
40+
return "UNKNOWN";
41+
case property_resultt::NOT_REACHABLE:
42+
return "UNREACHABLE";
43+
case property_resultt::PASS:
44+
return "PASS";
45+
case property_resultt::FAIL:
46+
return "FAIL";
47+
case property_resultt::ERROR:
48+
return "ERROR";
49+
}
50+
51+
UNREACHABLE;
52+
}
53+
54+
/// Return the properties in the goto model and initialize them to NOT_CHECKED
55+
propertiest initialize_properties(const abstract_goto_modelt &goto_model)
56+
{
57+
propertiest properties;
58+
const auto &goto_functions = goto_model.get_goto_functions();
59+
for(const auto &function_pair : goto_functions.function_map)
60+
{
61+
if(!function_pair.second.is_inlined() ||
62+
function_pair.first == goto_functionst::entry_point())
63+
{
64+
const goto_programt &goto_program = function_pair.second.body;
65+
66+
// need pointer to goto instruction
67+
forall_goto_program_instructions(i_it, goto_program)
68+
{
69+
if(!i_it->is_assert())
70+
continue;
71+
72+
property_infot &property =
73+
properties[i_it->source_location.get_property_id()];
74+
property.result = property_resultt::NOT_CHECKED;
75+
property.pc = i_it;
76+
}
77+
}
78+
}
79+
return properties;
80+
}

src/goto-checker/properties.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*******************************************************************\
2+
3+
Module: Properties
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Properties
11+
12+
#ifndef CPROVER_GOTO_CHECKER_PROPERTIES_H
13+
#define CPROVER_GOTO_CHECKER_PROPERTIES_H
14+
15+
#include <unordered_map>
16+
17+
#include <goto-programs/goto_model.h>
18+
19+
/// The result status of a property
20+
enum class property_resultt
21+
{
22+
/// The property was not checked (also used for initialization)
23+
NOT_CHECKED,
24+
/// The checker was unable to determine the status of the property
25+
UNKNOWN,
26+
/// The property was proven to be unreachable
27+
NOT_REACHABLE,
28+
/// The property was not violated
29+
PASS,
30+
/// The property was violated
31+
FAIL,
32+
/// An error occurred during goto checking
33+
ERROR
34+
};
35+
36+
std::string as_string(property_resultt result);
37+
38+
/// The result of goto checking and verifying
39+
enum class resultt
40+
{
41+
/// No property was violated, neither was there an error
42+
UNKNOWN,
43+
/// No properties were violated
44+
PASS,
45+
/// Some properties were violated
46+
FAIL,
47+
/// An error occurred during goto checking
48+
ERROR
49+
};
50+
51+
std::string as_string(resultt result);
52+
53+
struct property_infot
54+
{
55+
/// A pointer to the corresponding goto instruction
56+
goto_programt::const_targett pc;
57+
58+
/// A description (usually derived from the assertion's comment)
59+
std::string description;
60+
61+
/// The status of the property
62+
property_resultt result;
63+
};
64+
65+
/// A map of property IDs to property infos
66+
typedef std::unordered_map<irep_idt, property_infot> propertiest;
67+
68+
/// Returns the properties in the goto model
69+
propertiest initialize_properties(const abstract_goto_modelt &);
70+
71+
#endif // CPROVER_GOTO_CHECKER_PROPERTIES_H

0 commit comments

Comments
 (0)