Skip to content

Commit ade3057

Browse files
Merge pull request #2906 from hannes-steffenhagen-diffblue/invariant-with-diagnostics
Invariant with diagnostics
2 parents 2542d0d + 4082396 commit ade3057

File tree

6 files changed

+274
-106
lines changed

6 files changed

+274
-106
lines changed

regression/invariants/driver.cpp

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,31 @@ class structured_error_testt: public invariant_failedt
5656
}
5757
};
5858

59+
struct DiagnosticA
60+
{
61+
};
62+
struct DiagnosticB
63+
{
64+
};
65+
66+
template <>
67+
struct diagnostics_helpert<DiagnosticA>
68+
{
69+
static std::string diagnostics_as_string(const DiagnosticA &)
70+
{
71+
return "Diagnostic A";
72+
}
73+
};
74+
75+
template <>
76+
struct diagnostics_helpert<DiagnosticB>
77+
{
78+
static std::string diagnostics_as_string(const DiagnosticB &)
79+
{
80+
return "Diagnostic B";
81+
}
82+
};
83+
5984
/// Causes an invariant failure dependent on first argument value.
6085
/// One ignored argument is accepted to conform with the test.pl script,
6186
/// which would be the input source file for other cbmc driver programs.
@@ -92,21 +117,38 @@ int main(int argc, char** argv)
92117
else if(arg=="irep")
93118
INVARIANT_WITH_IREP(false, "error with irep", pointer_type(void_typet()));
94119
else if(arg == "invariant-diagnostics")
95-
INVARIANT(
120+
INVARIANT_WITH_DIAGNOSTICS(
96121
false,
97122
"invariant with diagnostics failure",
98123
"invariant diagnostics information");
99124
else if(arg == "precondition-diagnostics")
100-
PRECONDITION(false, "precondition diagnostics information");
125+
PRECONDITION_WITH_DIAGNOSTICS(
126+
false, "precondition diagnostics information");
101127
else if(arg == "postcondition-diagnostics")
102-
POSTCONDITION(false, "postcondition diagnostics information");
128+
POSTCONDITION_WITH_DIAGNOSTICS(
129+
false, "postcondition diagnostics information");
103130
else if(arg == "check-return-diagnostics")
104-
CHECK_RETURN(false, "check return diagnostics information");
131+
CHECK_RETURN_WITH_DIAGNOSTICS(
132+
false, "check return diagnostics information");
105133
else if(arg == "data-invariant-diagnostics")
106-
DATA_INVARIANT(
134+
DATA_INVARIANT_WITH_DIAGNOSTICS(
107135
false,
108136
"data invariant with diagnostics failure",
109137
"data invariant diagnostics information");
138+
else if(arg == "invariant-with-lots-of-diagnostics")
139+
INVARIANT_WITH_DIAGNOSTICS(
140+
false,
141+
"an invariant that fails",
142+
"diagnostic 1",
143+
"diagnostic 2",
144+
"diagnostic 3",
145+
"diagnostic 4");
146+
else if(arg == "invariant-with-custom-diagnostics")
147+
INVARIANT_WITH_DIAGNOSTICS(
148+
false,
149+
"an invariant with some custom diagnostics",
150+
DiagnosticA{},
151+
DiagnosticB{});
110152
else
111153
return 1;
112154
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
dummy_parameter.c
3+
invariant-with-lots-of-diagnostics
4+
^EXIT=(0|127|134|137)$
5+
^SIGNAL=0$
6+
--- begin invariant violation report ---
7+
Invariant check failed
8+
diagnostic 1
9+
diagnostic 2
10+
diagnostic 3
11+
diagnostic 4
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-custom-diagnostics
4+
^EXIT=(0|127|134|137)$
5+
^SIGNAL=0$
6+
--- begin invariant violation report ---
7+
Invariant check failed
8+
Diagnostic A
9+
Diagnostic B

src/util/dstring.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Author: Daniel Kroening, [email protected]
1313
#define CPROVER_UTIL_DSTRING_H
1414

1515
#include <iosfwd>
16+
#include <string>
1617

18+
#include "invariant.h"
1719
#include "string_container.h"
1820

1921
/// \ref dstringt has one field, an unsigned integer \ref no which is an index
@@ -198,4 +200,13 @@ struct hash<dstringt> // NOLINT(readability/identifiers)
198200
};
199201
}
200202

203+
template <>
204+
struct diagnostics_helpert<dstringt>
205+
{
206+
static std::string diagnostics_as_string(const dstringt &dstring)
207+
{
208+
return as_string(dstring);
209+
}
210+
};
211+
201212
#endif // CPROVER_UTIL_DSTRING_H

0 commit comments

Comments
 (0)