Skip to content

Add way to have irep pretty printed as diagnostic #2930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion regression/invariants/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ Author: Chris Smowton, [email protected]
#include <string>
#include <sstream>

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/invariant.h>
#include <util/invariant_utils.h>
#include <util/irep.h>
#include <util/std_expr.h>
#include <util/std_types.h>
#include <util/c_types.h>

/// An example of structured invariants-- this contains fields to
/// describe the error to a catcher, and also produces a human-readable
Expand Down Expand Up @@ -149,6 +152,15 @@ int main(int argc, char** argv)
"an invariant with some custom diagnostics",
DiagnosticA{},
DiagnosticB{});
else if(arg == "invariant-with-irep-diagnostics")
{
INVARIANT_WITH_DIAGNOSTICS(
false,
"an invariant with irep diagnostics",
irep_pretty_diagnosticst{
plus_exprt{from_integer(8, signedbv_typet(32)),
from_integer(13, signedbv_typet(32))}});
}
else
return 1;
}
9 changes: 9 additions & 0 deletions regression/invariants/invariant-irep-diagnostic/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
dummy_parameter.c
invariant-with-irep-diagnostics
^EXIT=(0|127|134|137)$
^SIGNAL=0$
--- begin invariant violation report ---
Invariant check failed
value: 00000000000000000000000000001000
value: 00000000000000000000000000001101
5 changes: 5 additions & 0 deletions src/util/irep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,3 +689,8 @@ std::string irept::pretty(unsigned indent, unsigned max_indent) const

return result;
}

irep_pretty_diagnosticst::irep_pretty_diagnosticst(const irept &irep)
: irep(irep)
{
}
15 changes: 15 additions & 0 deletions src/util/irep.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,19 @@ struct irep_full_eq
}
};

struct irep_pretty_diagnosticst
{
const irept &irep;
explicit irep_pretty_diagnosticst(const irept &irep);
};

template <>
struct diagnostics_helpert<irep_pretty_diagnosticst>
{
static std::string diagnostics_as_string(const irep_pretty_diagnosticst &irep)
{
return irep.irep.pretty();
}
};

#endif // CPROVER_UTIL_IREP_H