Skip to content

Commit 4cd1ae5

Browse files
Merge pull request #2930 from hannes-steffenhagen-diffblue/feature-irep_diagnostic
Add way to have irep pretty printed as diagnostic
2 parents d706891 + 1ba1da2 commit 4cd1ae5

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

regression/invariants/driver.cpp

Lines changed: 13 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,15 @@ 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+
{
157+
INVARIANT_WITH_DIAGNOSTICS(
158+
false,
159+
"an invariant with irep diagnostics",
160+
irep_pretty_diagnosticst{
161+
plus_exprt{from_integer(8, signedbv_typet(32)),
162+
from_integer(13, signedbv_typet(32))}});
163+
}
152164
else
153165
return 1;
154166
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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

src/util/irep.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,3 +689,8 @@ std::string irept::pretty(unsigned indent, unsigned max_indent) const
689689

690690
return result;
691691
}
692+
693+
irep_pretty_diagnosticst::irep_pretty_diagnosticst(const irept &irep)
694+
: irep(irep)
695+
{
696+
}

src/util/irep.h

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

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

0 commit comments

Comments
 (0)