Skip to content

Commit 273fff5

Browse files
author
Enrico Steffinlongo
committed
Generated new version of UNREACHABLE addressing error on GCC 12
1 parent 00f1d72 commit 273fff5

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/util/invariant.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,24 @@ CBMC_NORETURN void report_invariant_failure(
500500
EXPAND_MACRO(INVARIANT_STRUCTURED(CONDITION, TYPENAME, __VA_ARGS__))
501501

502502
/// 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
506521

507522
/// This condition should be used to document that assumptions that are
508523
/// made on goto_functions, goto_programs, exprts, etc. being well formed.

0 commit comments

Comments
 (0)