Skip to content

Commit 50631b2

Browse files
author
Enrico Steffinlongo
committed
Add UNREACHABLE_BECAUSE to fail with a reason
Add `UNREACHABLE_BECAUSE` assertion to fail with a reason to avoid using `INVARIANT(false, REASON)`.
1 parent e9434e0 commit 50631b2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/util/invariant.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ CBMC_NORETURN void report_invariant_failure(
509509
INVARIANT(false, "Unreachable"); \
510510
__builtin_unreachable(); \
511511
} while(false)
512+
# define UNREACHABLE_BECAUSE(REASON) \
513+
do \
514+
{ \
515+
INVARIANT(false, REASON); \
516+
__builtin_unreachable(); \
517+
} while(false)
512518
# define UNREACHABLE_STRUCTURED(TYPENAME, ...) \
513519
do \
514520
{ \
@@ -517,6 +523,7 @@ CBMC_NORETURN void report_invariant_failure(
517523
} while(false)
518524
#else
519525
# define UNREACHABLE INVARIANT(false, "Unreachable")
526+
# define UNREACHABLE_BECAUSE(REASON) INVARIANT(false, REASON);
520527
# define UNREACHABLE_STRUCTURED(TYPENAME, ...) \
521528
EXPAND_MACRO(INVARIANT_STRUCTURED(false, TYPENAME, __VA_ARGS__))
522529
#endif

0 commit comments

Comments
 (0)