Fixed weakest precondition for code_assertt#5847
Fixed weakest precondition for code_assertt#5847SaswatPadhi wants to merge 1 commit intodiffblue:developfrom
Conversation
The existing wp function treated an assert statement the same way as a skip statement. This commit fixes this behavior as per standard Hoare logic rules.
NlightNFotis
left a comment
There was a problem hiding this comment.
LGTM, with the caveat of the clang-format issued fixed.
martin-cs
left a comment
There was a problem hiding this comment.
Can we discuss what your understanding of the semantics of assert is?
This is not well documented but I think that assert is just a check; it does not alter the flow of control in any way (there are a number of reasons why I think this is the useful semantics). Thus your patch is correct for the original Floyd-Hoare logic rules but I don't think that is what we have.
|
Hi @martin-cs, I am not sure about the semantics of It seems kind of strange that |
|
Or may be I misunderstood @kroening. Probably he was pointing to a broader change -- changing the semantics of |
|
I would strongly oppose changing the semantics of assert because it will be a lot of work and there are current bits of functionality that cannot be replicated with the If you want this semantics, may I suggest you name it "assert-free-WP" or similar. I can see that it is a useful thing to have but I think it should be separate to the normal WP. PS If you are working on CHC, have you seen https://github.com/diffblue/cbmc/blob/develop/src/goto-instrument/horn_encoding.h ? Maybe Daniel has the patch that fills this in? |
|
This patch also seems consistent with the C/C++ semantics for |
Thanks, yes I am extending this file and I have handled many of the constructs that are currently not handled by the |
Thanks. Yes, currently for I read the documentation @ #2301 and understand the rationale behind the current semantics, although it's somewhat unsettling that it differs from the C semantics. The PR discusses goto statements though. So the same applies to |
|
[...]
I don't think anyone ever claimed that GOTO programs should have the same semantics as C programs? |
Codecov Report
@@ Coverage Diff @@
## develop #5847 +/- ##
========================================
Coverage 72.86% 72.86%
========================================
Files 1421 1421
Lines 154173 154173
========================================
Hits 112337 112337
Misses 41836 41836 Continue to review full report at Codecov.
|
But isn't this claim implicit, when we say it's a bounded model checker for C? I mean if we model programs differently, then our check might have totally different guarantees that may not hold over actual execution of the program. Although this particular case might be a non-issue, so please feel free to close this PR. |
|
Sorry, I must've misunderstood what this change was about during the meeting. I would agree with Martin that changing the meaning of assert would be a major breaking change that's likely to have a lot of unintended consequence elsewhere in the codebase as well as downstream. Whether or not we should change the meaning of assert is a discussion for another time, but it's certainly not something that should happen without prior discussion. |
|
On Fri, 2021-02-19 at 10:05 -0800, Saswat Padhi wrote:
> I don't think anyone ever claimed that GOTO programs should have
> the same semantics as C programs?
But isn't this claim implicit, when we say it's a bounded model
checker for C? I mean if we model programs differently, then our
check might have totally different guarantees that may not hold over
actual execution of the program.
I fear there may be a subtle miscommunication here. I think the point
@tautschnig was making was that the /primitives/ of GOTO don't have to
have the same semantics as C. However the over-all goal is to express
the semantics of C /using/ those primitives. Thus the results are
accurate w.r.t. ISO-9899+implementation defined behaviour but the
/means/ of computing those aren't necessarily a subset of C.
Cheers,
- Martin
|
|
That makes sense. Thanks @martin-cs! |
|
@martin-cs, @tautschnig: To preserve behavior, |
Indeed - I've now implemented this in #5866. |
|
Thanks, @tautschnig. There is still some issue with the WP computation -- I am thinking more about it and would bring it up during our meeting tomorrow / next DiffBlue meeting. Basically, the C statement |
|
[...]
Yes, that's what WP computation will need to deal with. It's the "ASSUME" that you should be able to derive preconditions from. |
This is, in fact, what jbmc is doing. I think changing the frontend to that may make sense, this'll change coverage results but probably not in a way anyone's going to complain about. |
|
@hannes-steffenhagen-diffblue agreed. There is a long-standing question / concern / issue with the correctness of traces / model checking after any undefined behaviour in C. |
|
Closing this PR for now. The WP seems consistent with the non-aborting Thanks everyone! |
The existing
wpfunction treated anassertstatement the same way as askipstatement. This commit fixes this behavior as per standard Hoare logic rules.