Skip to content

Commit 969825c

Browse files
Add way to have irep pretty printed as diagnostic
1 parent 20f05af commit 969825c

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

regression/invariants/driver.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ Author: Chris Smowton, [email protected]
1212
#include <string>
1313
#include <sstream>
1414

15+
#include <util/arith_tools.h>
16+
#include <util/c_types.h>
1517
#include <util/invariant.h>
1618
#include <util/invariant_utils.h>
19+
#include <util/irep.h>
20+
#include <util/std_expr.h>
1721
#include <util/std_types.h>
18-
#include <util/c_types.h>
1922

2023
/// An example of structured invariants-- this contains fields to
2124
/// describe the error to a catcher, and also produces a human-readable
@@ -149,6 +152,13 @@ int main(int argc, char** argv)
149152
"an invariant with some custom diagnostics",
150153
DiagnosticA{},
151154
DiagnosticB{});
155+
else if(arg == "invariant-with-irep-diagnostics")
156+
INVARIANT_WITH_DIAGNOSTICS(
157+
false,
158+
"an invariant with irep diagnostics",
159+
irep_pretty_diagnosticst{
160+
plus_exprt{from_integer(8, signedbv_typet(32)),
161+
from_integer(13, signedbv_typet(32))}});
152162
else
153163
return 1;
154164
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
dummy_parameter.c
3+
invariant-with-irep-diagnostics
4+
^EXIT=(0|127|134|137)$
5+
^SIGNAL=0$
6+
--- begin invariant violation report ---
7+
Invariant check failed
8+
value: 00000000000000000000000000001000
9+
value: 00000000000000000000000000001101
10+

src/util/irep.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,18 @@ struct irep_full_eq
463463
}
464464
};
465465

466+
struct irep_pretty_diagnosticst
467+
{
468+
const irept &irep;
469+
};
470+
471+
template <>
472+
struct diagnostics_helpert<irep_pretty_diagnosticst>
473+
{
474+
static std::string diagnostics_as_string(const irep_pretty_diagnosticst &irep)
475+
{
476+
return irep.irep.pretty();
477+
}
478+
};
479+
466480
#endif // CPROVER_UTIL_IREP_H

0 commit comments

Comments
 (0)