-
Notifications
You must be signed in to change notification settings - Fork 273
Abort after failing C assert #5866
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
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #5866 +/- ##
===========================================
- Coverage 76.74% 74.30% -2.44%
===========================================
Files 1579 1447 -132
Lines 182171 157796 -24375
===========================================
- Hits 139802 117257 -22545
+ Misses 42369 40539 -1830
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this requires a thorough documentation review since __CPROVER_assert
is now the default way to specify non-aborting properties. Some downstream CBMC users might not operate with abort-semantics in mind.
Side note: JBMC does something similar (in one of its modes)
cbmc/jbmc/src/java_bytecode/java_bytecode_convert_method.cpp
Lines 2444 to 2446 in f4edb72
// we translate athrow into | |
// ASSERT false; | |
// ASSUME false: |
@@ -2,8 +2,8 @@ int main() | |||
{ | |||
for(int i = 0; i < 10; ++i) | |||
{ | |||
assert(i != 5); | |||
assert(i != 8); | |||
__CPROVER_assert(i != 5, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Do we need a convenienve overload without the comment argument since __CPROVER_assert
is now the default way to specify non-aborting properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea to me
IMHO this sounds like the right way to go forward with this. I do also agree with @peterschrammel though that this requires us going through documentation and making sure we don't say anything wrong now, and for the other I think this should result in a major version bump. |
\[test.assertion.1\] line 3 assertion: SUCCESS | ||
\[test.assertion.2\] line 4 assertion: SUCCESS | ||
\[test.assertion.3\] line 5 assertion: FAILURE | ||
\[test.assertion.4\] line 6 assertion: FAILURE | ||
\[test.assertion.5\] line 7 assertion: FAILURE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we lost something useful and helpful here by not showing any detail of the assertion that failed? (I realise the empty messages may contribute to this, but with the comment of @peterschrammel above perhaps we should consider having the same behaviour in our override?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 these should give a message...
We are doing a similar assert/assume thing for Ada. As regards updating -- this always used to be how |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good and useful thing to do. I won't block this but I do agree with others that this needs to be clearly communicated (or, at least, "If you want a non-terminating check, use __CPROVER_assert()
").
One thought : it feels like assert
should be implementable in the C library (possibly with a macro to copy the expression into the string so that we don't have the problem with loss of messages that @TGWDB flagged). I am generally in favour of modelling going in the library in C where possible.
I have one small comment that I had mentioned to @tautschnig this morning: The semantics for
This means, if the It seems to me that |
@SaswatPadhi This is a sensible and a valid concern but I think that
|
c324b9a
to
9b215f7
Compare
37b5112
to
0e2eb40
Compare
Marking do-not-merge as this likely wants a major-version bump. Otherwise it should be ready for (re-)review. |
C's assert() should result in an abort() when the asserted condition evaluates to false. If we want to test multiple properties, including some failing ones, use __CPROVER_assert to not rely on any modelling of assert() that does not result in an abort().
The C standard specifies behaviour of the "assert" macro as resulting in an abort when the condition does not evaluate to true. Implement this behaviour by inserting assume(0) after assert(0). Fixes: diffblue#5505
We are considering to include this PR into version 6. However we should make sure that we do add the documentation specifying that |
This is a major undertaking with limited added value. Users could choose to add their own assert macro that exhibits this behaviour. Closing as we are unlikely to find time to work on this anytime soon. |
The C standard specifies behaviour of the "assert" macro as resulting in
an abort when the condition does not evaluate to true. Implement this
behaviour by inserting assume(0) after assert(0).
Fixes: #5505