-
Notifications
You must be signed in to change notification settings - Fork 277
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
Changes from all commits
1c222cb
7c15f2b
440093b
1a0f60d
b829f63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
dummy_parameter.c | ||
unreachable-because | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
--- begin invariant violation report --- | ||
Unreachable with explanation text | ||
Invariant check failed | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,9 +500,33 @@ CBMC_NORETURN void report_invariant_failure( | |
EXPAND_MACRO(INVARIANT_STRUCTURED(CONDITION, TYPENAME, __VA_ARGS__)) | ||
|
||
/// This should be used to mark dead code | ||
#define UNREACHABLE INVARIANT(false, "Unreachable") | ||
#define UNREACHABLE_STRUCTURED(TYPENAME, ...) \ | ||
EXPAND_MACRO(INVARIANT_STRUCTURED(false, TYPENAME, __VA_ARGS__)) | ||
#ifdef __GNUC__ | ||
// GCC 12 with -O0 fails reporting missing return when using UNREACHABLE. | ||
// Using __builtin_unreachable fixes this without breaking the invariant. | ||
# define UNREACHABLE \ | ||
do \ | ||
{ \ | ||
INVARIANT(false, "Unreachable"); \ | ||
__builtin_unreachable(); \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we instead be adding this to the expansion of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No as the invariant can actually be satisfied ( The problem is just related to GCC 12 with The only cases I found of this are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant was putting the |
||
} while(false) | ||
# define UNREACHABLE_BECAUSE(REASON) \ | ||
do \ | ||
{ \ | ||
INVARIANT(false, REASON); \ | ||
__builtin_unreachable(); \ | ||
} while(false) | ||
# define UNREACHABLE_STRUCTURED(TYPENAME, ...) \ | ||
do \ | ||
{ \ | ||
EXPAND_MACRO(INVARIANT_STRUCTURED(false, TYPENAME, __VA_ARGS__)); \ | ||
__builtin_unreachable(); \ | ||
} while(false) | ||
#else | ||
# define UNREACHABLE INVARIANT(false, "Unreachable") | ||
# define UNREACHABLE_BECAUSE(REASON) INVARIANT(false, REASON) | ||
# define UNREACHABLE_STRUCTURED(TYPENAME, ...) \ | ||
EXPAND_MACRO(INVARIANT_STRUCTURED(false, TYPENAME, __VA_ARGS__)) | ||
#endif | ||
|
||
/// This condition should be used to document that assumptions that are | ||
/// made on goto_functions, goto_programs, exprts, etc. being well formed. | ||
|
@@ -514,8 +538,17 @@ CBMC_NORETURN void report_invariant_failure( | |
#define DATA_INVARIANT_STRUCTURED(CONDITION, TYPENAME, ...) \ | ||
EXPAND_MACRO(INVARIANT_STRUCTURED(CONDITION, TYPENAME, __VA_ARGS__)) | ||
|
||
#define UNIMPLEMENTED_FEATURE(FEATURE) \ | ||
INVARIANT(false, std::string{"Reached unimplemented "} + (FEATURE)) | ||
#if __GNUC__ | ||
# define UNIMPLEMENTED_FEATURE(FEATURE) \ | ||
do \ | ||
{ \ | ||
INVARIANT(false, std::string{"Reached unimplemented "} + (FEATURE)); \ | ||
__builtin_unreachable(); \ | ||
} while(false) | ||
#else | ||
# define UNIMPLEMENTED_FEATURE(FEATURE) \ | ||
INVARIANT(false, std::string{"Reached unimplemented "} + (FEATURE)) | ||
#endif | ||
|
||
// Legacy annotations | ||
|
||
|
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? TheINVARIANT
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.