@@ -500,9 +500,24 @@ CBMC_NORETURN void report_invariant_failure(
500
500
EXPAND_MACRO (INVARIANT_STRUCTURED(CONDITION, TYPENAME, __VA_ARGS__))
501
501
502
502
// / This should be used to mark dead code
503
- #define UNREACHABLE INVARIANT (false , " Unreachable" )
504
- #define UNREACHABLE_STRUCTURED (TYPENAME, ...) \
505
- EXPAND_MACRO (INVARIANT_STRUCTURED(false , TYPENAME, __VA_ARGS__))
503
+ #ifdef __GNUC__
504
+ // GCC 12 with -O0 fails reporting missing return when using UNREACHABLE.
505
+ // Using __builtin_unreachable fixes this without breaking the invariant.
506
+ # define UNREACHABLE \
507
+ do { \
508
+ INVARIANT (false , " Unreachable" ); \
509
+ __builtin_unreachable (); \
510
+ } while (false )
511
+ # define UNREACHABLE_STRUCTURED (TYPENAME, ...) \
512
+ do { \
513
+ EXPAND_MACRO (INVARIANT_STRUCTURED (false , TYPENAME, __VA_ARGS__)); \
514
+ __builtin_unreachable (); \
515
+ } while (false )
516
+ #else
517
+ # define UNREACHABLE INVARIANT (false , " Unreachable" )
518
+ # define UNREACHABLE_STRUCTURED (TYPENAME, ...) \
519
+ EXPAND_MACRO (INVARIANT_STRUCTURED(false , TYPENAME, __VA_ARGS__))
520
+ #endif
506
521
507
522
// / This condition should be used to document that assumptions that are
508
523
// / made on goto_functions, goto_programs, exprts, etc. being well formed.
0 commit comments