Skip to content

Commit badcae8

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 badcae8

7 files changed

+347
-0
lines changed

src/goto-checker/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
SRC = bmc_util.cpp \
2+
incremental_goto_checker.cpp \
3+
goto_verifier.cpp \
4+
properties.cpp \
25
solver_factory.cpp \
36
symex_coverage.cpp \
47
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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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, an
23+
/// `incremental_goto_checkert` to iteratively determine the verification status
24+
/// of each property.
25+
class goto_verifiert
26+
{
27+
public:
28+
goto_verifiert() = delete;
29+
goto_verifiert(const goto_verifiert &) = delete;
30+
virtual ~goto_verifiert() = default;
31+
32+
/// Check whether all properties hold.
33+
/// \return PASS if all properties are PASS,
34+
/// FAIL if at least one property is FAIL and no property is ERROR,
35+
/// UNKNOWN if no property is FAIL or ERROR and
36+
/// at least one property is UNKNOWN,
37+
/// ERROR if at least one property is error.
38+
virtual resultt operator()() = 0;
39+
40+
/// Report results
41+
virtual void report() = 0;
42+
43+
/// Returns the properties
44+
const propertiest &get_properties()
45+
{
46+
return properties;
47+
}
48+
49+
protected:
50+
goto_verifiert(const optionst &, ui_message_handlert &);
51+
52+
const optionst &options;
53+
ui_message_handlert &ui_message_handler;
54+
messaget log;
55+
propertiest properties;
56+
};
57+
58+
#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: Incremental Goto Checker Interface
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Incremental 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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*******************************************************************\
2+
3+
Module: Incremental Goto Checker Interface
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Incremental 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 status, 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+
incremental_goto_checkert() = delete;
37+
incremental_goto_checkert(const incremental_goto_checkert &) = delete;
38+
virtual ~incremental_goto_checkert() = default;
39+
40+
enum class resultt
41+
{
42+
/// The goto checker may be able to find another FAILed property
43+
/// if operator() is called again.
44+
FOUND_FAIL,
45+
/// The goto checker has returned all results for the given set
46+
/// of properties.
47+
DONE
48+
};
49+
50+
/// Check whether the given properties with status NOT_CHECKED, UNKNOWN or
51+
/// properties newly discovered by `goto_checkert` hold.
52+
/// \param [out] properties: Properties updated to whether their status
53+
/// have been determined. Newly discovered properties are added.
54+
/// \return whether the goto checker found a violated property (FOUND_FAIL) or
55+
/// whether it is DONE with the given properties.
56+
/// After returning DONE, another call to operator() with the same
57+
/// properties will return DONE and leave the properties' status unchanged.
58+
/// If there is a property with status FAIL then its counterexample
59+
/// can be retrieved by calling `build_error_trace` before any
60+
/// subsequent call to operator().
61+
/// `goto_checkert` derivatives shall be implemented in a way such
62+
/// that repeated calls to operator() shall return when the next FAILed
63+
/// property has been found until eventually it does not find any
64+
/// failing properties any more.
65+
virtual resultt operator()(propertiest &properties) = 0;
66+
67+
/// Builds and returns the counterexample
68+
virtual goto_tracet build_error_trace() const = 0;
69+
70+
protected:
71+
incremental_goto_checkert(const optionst &, ui_message_handlert &);
72+
73+
const optionst &options;
74+
ui_message_handlert &ui_message_handler;
75+
messaget log;
76+
};
77+
78+
#endif // CPROVER_GOTO_CHECKER_INCREMENTAL_GOTO_CHECKER_H

src/goto-checker/properties.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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_statust status)
34+
{
35+
switch(status)
36+
{
37+
case property_statust::NOT_CHECKED:
38+
return "NOT CHECKED";
39+
case property_statust::UNKNOWN:
40+
return "UNKNOWN";
41+
case property_statust::NOT_REACHABLE:
42+
return "UNREACHABLE";
43+
case property_statust::PASS:
44+
return "PASS";
45+
case property_statust::FAIL:
46+
return "FAIL";
47+
case property_statust::ERROR:
48+
return "ERROR";
49+
}
50+
51+
UNREACHABLE;
52+
}
53+
54+
property_infot::property_infot(
55+
goto_programt::const_targett pc,
56+
std::string description,
57+
property_statust status)
58+
: pc(pc), description(std::move(description)), status(status)
59+
{
60+
}
61+
62+
/// Return the properties in the goto model and initialize them to NOT_CHECKED
63+
propertiest initialize_properties(const abstract_goto_modelt &goto_model)
64+
{
65+
propertiest properties;
66+
const auto &goto_functions = goto_model.get_goto_functions();
67+
for(const auto &function_pair : goto_functions.function_map)
68+
{
69+
// don't collect properties from inlined functions
70+
if(function_pair.second.is_inlined())
71+
continue;
72+
73+
const goto_programt &goto_program = function_pair.second.body;
74+
75+
// need pointer to goto instruction
76+
forall_goto_program_instructions(i_it, goto_program)
77+
{
78+
if(!i_it->is_assert())
79+
continue;
80+
81+
std::string description = id2string(i_it->source_location.get_comment());
82+
if(description.empty())
83+
description = "assertion";
84+
properties.emplace(
85+
i_it->source_location.get_property_id(),
86+
property_infot{i_it, description, property_statust::NOT_CHECKED});
87+
}
88+
}
89+
return properties;
90+
}

src/goto-checker/properties.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 status of a property
20+
enum class property_statust
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_statust);
37+
38+
/// The result of goto 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);
52+
53+
struct property_infot
54+
{
55+
property_infot(
56+
goto_programt::const_targett pc,
57+
std::string description,
58+
property_statust status);
59+
60+
/// A pointer to the corresponding goto instruction
61+
goto_programt::const_targett pc;
62+
63+
/// A description (usually derived from the assertion's comment)
64+
std::string description;
65+
66+
/// The status of the property
67+
property_statust status;
68+
};
69+
70+
/// A map of property IDs to property infos
71+
typedef std::unordered_map<irep_idt, property_infot> propertiest;
72+
73+
/// Returns the properties in the goto model
74+
propertiest initialize_properties(const abstract_goto_modelt &);
75+
76+
#endif // CPROVER_GOTO_CHECKER_PROPERTIES_H

0 commit comments

Comments
 (0)