-
Notifications
You must be signed in to change notification settings - Fork 273
Handle all enum values in switch/case [blocks: #2310] #2548
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
What crazy compiler won't let you use |
42e2381
to
ca1ceb9
Compare
I'd say that's a perfectly sane compiler as far as enums are concerned: it helps you not forget about values that were added to the enum type later on, but aren't handled in |
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.
Passed Diffblue compatibility checks (cbmc commit: ca1ceb9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/78386231
your branch name has a |
Yes, Visual Studio does complain about cases not being handled (despite the |
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.
Fair point, in that case I support the change. If you do this, consider enabling -Wswitch-enum in our GCC configs so any mistake is detected early, rather than presenting developers with an annoying stumbling block when the shorthand is only flagged on Windows.
src/ansi-c/c_typecast.cpp
Outdated
case FIXEDBV: | ||
case LARGE_UNSIGNED_INT: | ||
case LARGE_SIGNED_INT: | ||
return; // do nothing |
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.
Weird indent
ca1ceb9
to
b5b3ff3
Compare
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.
Generally approve of the change. A minor nit being a possible independent commit being included in this PR, but given the PR is one of a series of nice clean ups related to compiler warnings, I'm not going to block this PR :-)
@@ -496,6 +496,7 @@ static mp_integer max_value(const typet &type) | |||
else if(type.id() == ID_unsignedbv) | |||
return to_unsignedbv_type(type).largest(); | |||
UNREACHABLE; | |||
return 0; |
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.
It seems like this change (and the others in this commit) are somewhat independent of the stated purpose of this PR or are these warnings triggered by the change in switch/case statements?
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'm afraid they are: making Visual Studio happy that all cases are covered implies that the default
can be removed. Doing so makes GCC unhappy as it thinks code becomes reachable. The specific code that you highlighted above, though, is not linked to one of those default
-is-gone cases, but did fit the same topic. Let me know if you'd want me to dissect it.
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.
Thanks for the clarification - I'm fine with this PR as it is :-)
b5b3ff3
to
b08eabb
Compare
e31bd35
to
04f3ac3
Compare
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.
This PR failed Diffblue compatibility checks (cbmc commit: 04f3ac3).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/78602309
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.
Common spurious failures:
- the cbmc commit has disappeared in the mean time (e.g. in a force-push)
- the author is not in the list of contributors (e.g. first-time contributors).
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 wish I could say I was surprised by this. See also #4323 for a discussion of what to do about this.
@kroening @peterschrammel Please review commit-by-commit, where you may wish to skip the clang-format-only commit. |
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.
This PR failed Diffblue compatibility checks (cbmc commit: 7b51b0c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/103086699
Status will be re-evaluated on next push.
Common spurious failures:
-
the cbmc commit has disappeared in the mean time (e.g. in a force-push)
-
the author is not in the list of contributors (e.g. first-time contributors).
-
the compatibility was already broken by an earlier merge.
16f41ce
to
0727459
Compare
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 0727459).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/103501248
0727459
to
bf2df04
Compare
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.
This PR failed Diffblue compatibility checks (cbmc commit: bf2df04).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/104505124
Status will be re-evaluated on next push.
Common spurious failures:
-
the cbmc commit has disappeared in the mean time (e.g. in a force-push)
-
the author is not in the list of contributors (e.g. first-time contributors).
-
the compatibility was already broken by an earlier merge.
bf2df04
to
09b2fe0
Compare
This is now consistent with the warnings that Visual Studio would generate, which warns about missing enum cases in switch/case even when a default: is present.
We should not re-indent a large number of lines of code just because some case statements were added. Silence clang-format for these instead.
There are a number of reasons why instruction types were left out of these case statements : 1. Ignoring this instruction is generally a valid overapproximation. 2. Ignoring this instruction is a valid overapproximation for this domain. 3. The instruction is assumed to not be present due to preceding passes. 4. The instruction should never appear in any valid goto program. 5. The instruction is newer than the analysis code and was forgotten. This patch tries to correctly document which of these apply.
09b2fe0
to
3a333a2
Compare
This takes us back to the behaviour prior to this series of commits, and effectively is a to-do list to be addressed. We should either handle the cases, or get rid of the instruction type.
No description provided.