Skip to content

Commit b218405

Browse files
author
thenewone
committed
YT-23346: Introduce YT_ASSUME and YT_UNREACHABLE macros.
Y_ASSUME and Y_UNREACHABLE macros are platform-independent ways to give a hint for a compiler about some value or state. Compilier may use that hint for optimization. On the other hand if the hint is wrong it may lead to undefined behavior. YT_ASSUME and YT_UNREACHABLE are wrappers around Y_ASSUME and Y_UNREACHABLE that actually check that the hint is correct in debug build. That introduces some code safety and at the same time allows certain optimization in optimized build. commit_hash:2d0969361910a10a870bae226d838d494e656edb
1 parent 2c567f2 commit b218405

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/cpp/yt/assert/assert.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ void AssertTrapImpl(
5555
} \
5656
} while (false)
5757

58+
//! Behaves as |YT_ASSERT| in debug mode and as |Y_ASSUME| in release.
59+
#ifdef NDEBUG
60+
#define YT_ASSUME(expr) Y_ASSUME(expr)
61+
#else
62+
#define YT_ASSUME(expr) YT_ASSERT(expr)
63+
#endif
64+
65+
//! Behaves as |YT_ASSERT(false)| in debug mode and as |Y_UNREACHABLE| in release.
66+
#ifdef NDEBUG
67+
#define YT_UNREACHABLE() Y_UNREACHABLE()
68+
#else
69+
#define YT_UNREACHABLE() YT_ASSERT(false)
70+
#endif
71+
5872
//! Fatal error code marker. Abnormally terminates the current process.
5973
#ifdef YT_COMPILING_UDF
6074
#define YT_ABORT() __YT_BUILTIN_ABORT()

0 commit comments

Comments
 (0)