Skip to content

Fixup GCC 12 errors #7665

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

Conversation

esteffin
Copy link
Contributor

@esteffin esteffin commented Apr 12, 2023

GCC 12 when using -O0 fails because of a missing-return-statement warning caused by the implementation of INVARIANT(false).

This is because the condition if (true) is not considered exahustive.

The solution involves marking the unreachable path as __builtin_unreachable().

This PR also replaces some INVARIANT(false, REASON) statement used to have UNREACHABLE, but with a reason.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • 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).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@esteffin esteffin force-pushed the esteffin/gcc-12-unreachable-fix branch from 4fbde8d to 0a8a0f9 Compare April 12, 2023 23:58
@codecov
Copy link

codecov bot commented Apr 13, 2023

Codecov Report

Patch coverage has no change and project coverage change: +0.09 🎉

Comparison is base (68af7a4) 78.42% compared to head (b829f63) 78.51%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7665      +/-   ##
===========================================
+ Coverage    78.42%   78.51%   +0.09%     
===========================================
  Files         1674     1674              
  Lines       191935   191933       -2     
===========================================
+ Hits        150521   150704     +183     
+ Misses       41414    41229     -185     
Impacted Files Coverage Δ
src/solvers/smt2/smt2_conv.cpp 67.39% <ø> (+0.02%) ⬆️
...solvers/strings/string_format_builtin_function.cpp 73.10% <ø> (+0.16%) ⬆️
src/util/invariant.h 95.55% <ø> (ø)

... and 10 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

// GCC 12 with -O0 fails reporting missing return when using UNREACHABLE.
// Using __builtin_unreachable fixes this without breaking the invariant.
# define UNREACHABLE \
do \
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a new do ... while(false) block here? The INVARIANT definition has one of its own.

Would it make more sense to just have a block { INVARIANT(false, "Unreachable"); __builtin_unreachable(); } or am I mistaken?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The do { ... } while (false) in the macros is because it allows a ; (semicolon) after the macro, but does not require it (it works with both).

It is a common C methodology.

@NlightNFotis NlightNFotis linked an issue Apr 13, 2023 that may be closed by this pull request
@esteffin esteffin force-pushed the esteffin/gcc-12-unreachable-fix branch 3 times, most recently from ec02ef9 to a02416f Compare April 17, 2023 14:23
@esteffin esteffin marked this pull request as ready for review April 17, 2023 14:25
Enrico Steffinlongo added 2 commits April 17, 2023 15:27
GCC 12 when using `-O0` fails because of a missing-return-statement
warning caused by the implementation of `INVARIANT(false)`.
This is because the condition `if (true)` is not considered exahustive.
The solution involves marking the unreachable path as
`__builtin_unreachable()`.
GCC 12 when using `-O0` fails because of a missing-return-statement
warning caused by the implementation of `INVARIANT(false)`.
This is because the condition `if (true)` is not considered exahustive.
The solution involves marking the unreachable path as
`__builtin_unreachable()`.
@esteffin esteffin force-pushed the esteffin/gcc-12-unreachable-fix branch from a02416f to b3aa8e1 Compare April 17, 2023 14:28
@esteffin esteffin changed the title GCC 12 fixup Fixup GCC 12 errors Apr 17, 2023
@NlightNFotis NlightNFotis enabled auto-merge April 17, 2023 14:55
Enrico Steffinlongo added 3 commits April 18, 2023 10:37
Add `UNREACHABLE_BECAUSE` assertion to fail with a reason to avoid using
`INVARIANT(false, REASON)`.
@esteffin esteffin force-pushed the esteffin/gcc-12-unreachable-fix branch from b3aa8e1 to b829f63 Compare April 18, 2023 09:38
do \
{ \
INVARIANT(false, "Unreachable"); \
__builtin_unreachable(); \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we instead be adding this to the expansion of the INVARIANT macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No as the invariant can actually be satisfied (INVARIANT(condition, "some reason") succeed when condition is true).

The problem is just related to GCC 12 with -O0 refusing to statically resolve cases of the form if (true) { <terminate> }.

The only cases I found of this are UNREACHABLE, UNIMPLEMENTED_FEATURE and some INVARIANT(false, "unreachable because") and they have all been fixed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What I meant was putting the __builtin_unreachable() inside the if(!(CONDITION)) branch, which wouldn't have the problem of the invariant being satisfied. Wouldn't that have worked? (It's possible that GCC's reachability analysis will remain confused in that case.)

@NlightNFotis NlightNFotis merged commit d2d7f76 into diffblue:develop Apr 18, 2023
@esteffin esteffin deleted the esteffin/gcc-12-unreachable-fix branch April 18, 2023 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build fails when using GCC 12
6 participants