Skip to content

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

Merged
merged 6 commits into from
May 1, 2019

Conversation

tautschnig
Copy link
Collaborator

No description provided.

@smowton
Copy link
Contributor

smowton commented Jul 7, 2018

What crazy compiler won't let you use default:?

@tautschnig
Copy link
Collaborator Author

What crazy compiler won't let you use default:?

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 switch statements. But I do accept that I might be the only one thinking this is a better approach.

Copy link
Contributor

@allredj allredj left a 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

@smowton
Copy link
Contributor

smowton commented Jul 9, 2018

your branch name has a vs- prefix though, does that imply MSVC was complaining?

@tautschnig
Copy link
Collaborator Author

[...] does that imply MSVC was complaining?

Yes, Visual Studio does complain about cases not being handled (despite the default).

Copy link
Contributor

@smowton smowton left a 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.

case FIXEDBV:
case LARGE_UNSIGNED_INT:
case LARGE_SIGNED_INT:
return; // do nothing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird indent

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a 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;
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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 :-)

@tautschnig tautschnig force-pushed the vs-switch-case branch 3 times, most recently from e31bd35 to 04f3ac3 Compare July 10, 2018 17:04
Copy link
Contributor

@allredj allredj left a 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).

Copy link
Collaborator

@martin-cs martin-cs left a 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.

@tautschnig
Copy link
Collaborator Author

@kroening @peterschrammel Please review commit-by-commit, where you may wish to skip the clang-format-only commit.

Copy link
Contributor

@allredj allredj left a 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.

@peterschrammel peterschrammel removed their assignment Mar 6, 2019
@tautschnig tautschnig force-pushed the vs-switch-case branch 2 times, most recently from 16f41ce to 0727459 Compare March 7, 2019 07:54
Copy link
Contributor

@allredj allredj left a 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

Copy link
Contributor

@allredj allredj left a 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.

tautschnig and others added 5 commits April 30, 2019 23:55
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.
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.
@tautschnig tautschnig merged commit 07c5e1d into diffblue:develop May 1, 2019
@tautschnig tautschnig deleted the vs-switch-case branch May 1, 2019 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants