-
Notifications
You must be signed in to change notification settings - Fork 274
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
Fixup GCC 12 errors #7665
Conversation
4fbde8d
to
0a8a0f9
Compare
Codecov ReportPatch coverage has no change and project coverage change:
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
... 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. |
// GCC 12 with -O0 fails reporting missing return when using UNREACHABLE. | ||
// Using __builtin_unreachable fixes this without breaking the invariant. | ||
# define UNREACHABLE \ | ||
do \ |
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.
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?
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.
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.
ec02ef9
to
a02416f
Compare
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()`.
a02416f
to
b3aa8e1
Compare
Add `UNREACHABLE_BECAUSE` assertion to fail with a reason to avoid using `INVARIANT(false, REASON)`.
b3aa8e1
to
b829f63
Compare
do \ | ||
{ \ | ||
INVARIANT(false, "Unreachable"); \ | ||
__builtin_unreachable(); \ |
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.
Shouldn't we instead be adding this to the expansion of the INVARIANT
macro?
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.
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.
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.
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.)
GCC 12 when using
-O0
fails because of a missing-return-statement warning caused by the implementation ofINVARIANT(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 haveUNREACHABLE
, but with a reason.