forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add invariant helper that pretty-prints an irep
- Loading branch information
Showing
7 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ Author: Chris Smowton, [email protected] | |
#include <string> | ||
#include <sstream> | ||
#include <util/invariant.h> | ||
#include <util/invariant_utils.h> | ||
#include <util/std_types.h> | ||
|
||
/// An example of structured invariants-- this contains fields to | ||
/// describe the error to a catcher, and also produces a human-readable | ||
|
@@ -83,6 +85,8 @@ int main(int argc, char** argv) | |
DATA_INVARIANT_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT | ||
else if(arg=="data-invariant-string") | ||
DATA_INVARIANT(false, "Test invariant failure"); | ||
else if(arg=="irep") | ||
INVARIANT_WITH_IREP(false, "error with irep", pointer_typet(void_typet())); | ||
else | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CORE | ||
dummy_parameter.c | ||
irep | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Invariant check failed | ||
error with irep | ||
pointer | ||
0: empty | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*******************************************************************\ | ||
Module: Invariant helper utilities | ||
Author: Chris Smowton, [email protected] | ||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Invariant helper utilities | ||
|
||
#include "invariant_utils.h" | ||
|
||
std::string pretty_print_invariant_with_irep( | ||
const irept &problem_node, | ||
const std::string &description) | ||
{ | ||
if(problem_node.is_nil()) | ||
return description; | ||
else | ||
{ | ||
std::string ret=description; | ||
ret+="\nProblem irep:\n"; | ||
ret+=problem_node.pretty(0,0); | ||
return ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*******************************************************************\ | ||
Module: Invariant helper utilities | ||
Author: Chris Smowton, [email protected] | ||
\*******************************************************************/ | ||
|
||
#ifndef CPROVER_UTIL_INVARIANT_TYPES_H | ||
#define CPROVER_UTIL_INVARIANT_TYPES_H | ||
|
||
#include "invariant.h" | ||
|
||
#include <util/irep.h> | ||
|
||
#include <string> | ||
|
||
/// Produces a plain string error description from an irep and some | ||
/// explanatory text. If `problem_node` is nil, returns `description`. | ||
/// \param problem_node: irep to pretty-print | ||
/// \param description: descriptive text to prepend | ||
/// \return error message | ||
std::string pretty_print_invariant_with_irep( | ||
const irept &problem_node, | ||
const std::string &description); | ||
|
||
/// Equivalent to | ||
/// `INVARIANT_STRUCTURED(CONDITION, invariant_failedt, | ||
/// pretty_print_invariant_with_irep(IREP, DESCRIPTION))` | ||
#define INVARIANT_WITH_IREP(CONDITION, DESCRIPTION, IREP) \ | ||
INVARIANT_STRUCTURED( \ | ||
CONDITION, \ | ||
invariant_failedt, \ | ||
pretty_print_invariant_with_irep((IREP), (DESCRIPTION))) | ||
|
||
/// See `INVARIANT_WITH_IREP` | ||
#define PRECONDITION_WITH_IREP(CONDITION, DESCRIPTION, IREP) \ | ||
INVARIANT_WITH_IREP((CONDITION), (DESCRIPTION), (IREP)) | ||
#define POSTCONDITION_WITH_IREP(CONDITION, DESCRIPTION, IREP) \ | ||
INVARIANT_WITH_IREP((CONDITION), (DESCRIPTION), (IREP)) | ||
#define CHECK_RETURN_WITH_IREP(CONDITION, DESCRIPTION, IREP) \ | ||
INVARIANT_WITH_IREP((CONDITION), (DESCRIPTION), (IREP)) | ||
#define UNREACHABLE_WITH_IREP(CONDITION, DESCRIPTION, IREP) \ | ||
INVARIANT_WITH_IREP((CONDITION), (DESCRIPTION), (IREP)) | ||
#define DATA_INVARIANT_WITH_IREP(CONDITION, DESCRIPTION, IREP) \ | ||
INVARIANT_WITH_IREP((CONDITION), (DESCRIPTION), (IREP)) | ||
|
||
#endif |