Skip to content

Commit c54e65f

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 57c66e2 commit c54e65f

File tree

7 files changed

+323
-1
lines changed

7 files changed

+323
-1
lines changed

src/goto-checker/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
SRC = solver_factory.cpp \
1+
SRC = goto_checker.cpp \
2+
goto_verifier.cpp \
3+
properties.cpp \
4+
solver_factory.cpp \
25
# Empty last line
36

47
INCLUDES= -I ..

src/goto-checker/goto_checker.cpp

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 "goto_checker.h"
13+
14+
goto_checkert::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+
}

src/goto-checker/goto_checker.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
#ifndef CPROVER_GOTO_CHECKER_GOTO_CHECKER_H
13+
#define CPROVER_GOTO_CHECKER_GOTO_CHECKER_H
14+
15+
#include <goto-programs/goto_trace.h>
16+
17+
#include <util/options.h>
18+
#include <util/ui_message.h>
19+
20+
#include "properties.h"
21+
22+
/// An implementation of `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 `goto_checkert` is responsible for maintaining
26+
/// the state of the analysis that it performs (e.g. goto-symex, solver, etc).
27+
/// It is not responsible for maintaining outcomes (e.g. property results,
28+
/// counterexamples, etc). However, an implementation may restrict the
29+
/// sets of properties it is asked to check (e.g. only sequences of subsets).
30+
class goto_checkert
31+
{
32+
public:
33+
enum class statust
34+
{
35+
/// The goto checker may be able to determine the results for more
36+
/// properties if operator() is called again.
37+
HAVE_MORE,
38+
/// The goto checker has returned all results for the given set
39+
/// of properties.
40+
DONE
41+
};
42+
43+
/// Check whether the given properties with status UNKNOWN or newly
44+
/// discovered properties hold
45+
/// \param [out] properties: Updates those properties whose
46+
/// results have been determined. Newly discovered properties are added.
47+
/// \return whether the goto checker may HAVE_MORE results or
48+
/// whether it is DONE with the given properties.
49+
/// After returning DONE, another call to operator() with the same
50+
/// properties will return DONE and leave the properties' results unchanged.
51+
/// If there is a property with status FAIL then its counterexample
52+
/// can be retrieved by calling `build_error_trace` before any
53+
/// subsequent call to operator().
54+
/// `goto_checkert` derivatives shall be implemented in a way such
55+
/// that repeated calls to operator() shall return the next FAILed
56+
/// property until eventually not returning any FAILing properties.
57+
virtual statust operator()(propertiest &properties) = 0;
58+
59+
/// This builds and returns the counterexample
60+
virtual goto_tracet build_error_trace() const = 0;
61+
62+
protected:
63+
goto_checkert(const optionst &, ui_message_handlert &);
64+
65+
const optionst &options;
66+
ui_message_handlert &ui_message_handler;
67+
messaget log;
68+
};
69+
70+
#endif // CPROVER_GOTO_CHECKER_GOTO_CHECKER_H

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

src/goto-checker/properties.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
std::string as_string(resultt result)
15+
{
16+
switch(result)
17+
{
18+
case resultt::UNKNOWN:
19+
return "UNKNOWN";
20+
case resultt::PASS:
21+
return "PASS";
22+
case resultt::FAIL:
23+
return "FAIL";
24+
case resultt::ERROR:
25+
return "ERROR";
26+
}
27+
28+
UNREACHABLE;
29+
}
30+
31+
std::string as_string(property_resultt result)
32+
{
33+
switch(result)
34+
{
35+
case property_resultt::NOT_REACHED:
36+
return "NOT REACHED";
37+
case property_resultt::UNKNOWN:
38+
return "UNKNOWN";
39+
case property_resultt::NOT_REACHABLE:
40+
return "UNREACHABLE";
41+
case property_resultt::PASS:
42+
return "PASS";
43+
case property_resultt::FAIL:
44+
return "FAIL";
45+
case property_resultt::ERROR:
46+
return "ERROR";
47+
}
48+
49+
UNREACHABLE;
50+
}
51+
52+
propertiest initialize_properties(const goto_modelt &goto_model)
53+
{
54+
propertiest properties;
55+
forall_goto_functions(it, goto_model.goto_functions)
56+
{
57+
if(
58+
!it->second.is_inlined() ||
59+
it->first == goto_model.goto_functions.entry_point())
60+
{
61+
const goto_programt &goto_program = it->second.body;
62+
63+
forall_goto_program_instructions(i_it, goto_program)
64+
{
65+
if(!i_it->is_assert())
66+
continue;
67+
68+
const source_locationt &source_location = i_it->source_location;
69+
70+
irep_idt property_id = source_location.get_property_id();
71+
72+
property_infot &property = properties[property_id];
73+
property.result = property_resultt::NOT_REACHED;
74+
property.location = i_it;
75+
}
76+
}
77+
}
78+
return properties;
79+
}

src/goto-checker/properties.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
class json_objectt;
20+
class xmlt;
21+
22+
/// The result status of a property
23+
enum class property_resultt
24+
{
25+
/// The property was not reached (also used for initialization)
26+
NOT_REACHED,
27+
/// The status of the property is unknown
28+
UNKNOWN,
29+
/// The property was proven to be unreachable
30+
NOT_REACHABLE,
31+
/// The property was not violated
32+
PASS,
33+
/// The property was violated
34+
FAIL,
35+
/// An error occurred during goto checking
36+
ERROR
37+
};
38+
39+
std::string as_string(property_resultt result);
40+
41+
/// The result of goto checking and verifying
42+
enum class resultt
43+
{
44+
/// No property was violated, neither was there an error
45+
UNKNOWN,
46+
/// No properties were violated
47+
PASS,
48+
/// Some properties were violated
49+
FAIL,
50+
/// An error occurred during goto checking
51+
ERROR
52+
};
53+
54+
std::string as_string(resultt result);
55+
56+
struct property_infot
57+
{
58+
/// A pointer to the corresponding goto instruction
59+
goto_programt::const_targett location;
60+
61+
/// A description (usually derived from the assertion's comment)
62+
std::string description;
63+
64+
/// The status of the property
65+
property_resultt result;
66+
};
67+
68+
/// A map of property IDs to property infos
69+
typedef std::unordered_map<irep_idt, property_infot> propertiest;
70+
71+
/// Returns the properties in the goto model
72+
propertiest initialize_properties(const goto_modelt &);
73+
74+
#endif // CPROVER_GOTO_CHECKER_PROPERTIES_H

0 commit comments

Comments
 (0)