Skip to content

Avoid warning about not returning a value [blocks: #2548]#3414

Merged
tautschnig merged 5 commits intodiffblue:developfrom
tautschnig:add-return-value
Dec 20, 2018
Merged

Avoid warning about not returning a value [blocks: #2548]#3414
tautschnig merged 5 commits intodiffblue:developfrom
tautschnig:add-return-value

Conversation

@tautschnig
Copy link
Collaborator

Compilers differ in their ability to infer dead code, and the use of INVARIANT
etc. may result in end-of-function being reachable when they are configured
as no-ops. Make compilers happy, even when that may result in statements that
really shouldn't be reachable.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@kroening
Copy link
Collaborator

Won't that backfire, i.e., generate warnings about dead code?

@tautschnig
Copy link
Collaborator Author

Won't that backfire, i.e., generate warnings about dead code?

Not as far as I can tell, but maybe #2548 has other changes hiding such warnings, so we'll see when CI passes over here (where there really is just this one 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.

✔️
Passed Diffblue compatibility checks (cbmc commit: 0941f7b).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/91377050

Copy link
Member

@peterschrammel peterschrammel left a comment

Choose a reason for hiding this comment

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

That's quite awkward. Hm... We could have a variant of these macros that take the return value to make this less ugly (but maybe also more confusing).

@kroening
Copy link
Collaborator

I am wondering whether the goal here can be achieved by means of the right compiler annotation for "UNREACHABLE" for Visual Studio?
Or turn off the "missing return value" warning in UNREACHABLE?

@smowton
Copy link
Contributor

smowton commented Nov 19, 2018

Some use of __declspec(noreturn) on a wrapper function ought to do the trick AFAICT

@kroening
Copy link
Collaborator

@smowton these functions will return, just somewhere else, with a return statement. It needs to be an annotation that says "I promise we won't get here". It might be doable to do that with a throw on VS.

@smowton
Copy link
Contributor

smowton commented Nov 19, 2018

? The important thing here is if we somehow hit an UNREACHABLE then control will not return to the callsite. That should stop VS from wanting a return statement.

@kroening
Copy link
Collaborator

The relevant function already has a __declspec(noreturn). The problem appears to be that MSVC can't infer that

if(!(CONDITION))
   invariant_violated...(...);

doesn't have a successor for CONDITION = false.

@kroening
Copy link
Collaborator

@tautschnig Special-casing the UNREACHABLE macro appears to work!

@tautschnig
Copy link
Collaborator Author

@kroening I believe I have now implemented what you meant by special-casing, but please do confirm.

@tautschnig tautschnig removed their assignment Dec 19, 2018
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: 0aad92f).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/95263703

@tautschnig
Copy link
Collaborator Author

Marking do-not-merge: I was likely mislead, the fix might be much simpler, investigating in #2310.

We previously never set noreturn for Visual Studio.
UNREACHABLE will throw an exception if such an instruction were actually
reached.
Also clean up the earlier if(...) return true; return false;
All earlier branches end in a return statement.
@tautschnig
Copy link
Collaborator Author

@kroening @owen-jones-diffblue @smowton @kroening You might all want to take another look as I have completely reworked the commits in this PR. The proper fix was much simpler than the intermediate versions that I had, and to an extent boils down to fixing a single typo...

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: c805422).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/95446748

@tautschnig tautschnig merged commit ca49d2e into diffblue:develop Dec 20, 2018
@tautschnig tautschnig deleted the add-return-value branch December 20, 2018 19:29
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.

6 participants