diff options
author | Adam Midvidy <amidvidy@gmail.com> | 2015-04-27 10:54:03 -0400 |
---|---|---|
committer | Adam Midvidy <amidvidy@gmail.com> | 2015-04-28 18:10:43 -0400 |
commit | 549889cef2d424790cdf82c4a4d372137aaa0439 (patch) | |
tree | 1787b35ebba3492da20459cfc2f05c9271b4e7ea /src/mongo/platform | |
parent | 7c15941e120f0c72d66a2f13c21b6f59a64a492d (diff) | |
download | mongo-549889cef2d424790cdf82c4a4d372137aaa0439.tar.gz |
SERVER-18219 hint to GCC that WCE loops will actually return
Diffstat (limited to 'src/mongo/platform')
-rw-r--r-- | src/mongo/platform/compiler.h | 14 | ||||
-rw-r--r-- | src/mongo/platform/compiler_gcc.h | 2 | ||||
-rw-r--r-- | src/mongo/platform/compiler_msvc.h | 2 |
3 files changed, 18 insertions, 0 deletions
diff --git a/src/mongo/platform/compiler.h b/src/mongo/platform/compiler.h index f4868acf432..d261a1781e3 100644 --- a/src/mongo/platform/compiler.h +++ b/src/mongo/platform/compiler.h @@ -118,6 +118,20 @@ * shared libraries. * * Same correct/incorrect usage as for MONGO_COMPILER_API_EXPORT. + * + * MONGO_COMPILER_UNREACHABLE + * + * Instructs the compiler that a line of code will never be reached. + * + * + * Example: + * // code above checks that expr can only be FOO or BAR + * switch (expr) { + * case FOO: { ... } + * case BAR: { ... } + * default: + * MONGO_COMPILER_UNREACHABLE; + * */ #if defined(_MSC_VER) diff --git a/src/mongo/platform/compiler_gcc.h b/src/mongo/platform/compiler_gcc.h index 431465893c9..553f599b335 100644 --- a/src/mongo/platform/compiler_gcc.h +++ b/src/mongo/platform/compiler_gcc.h @@ -64,3 +64,5 @@ #define MONGO_likely(x) static_cast<bool>(__builtin_expect(static_cast<bool>(x), 1)) #define MONGO_unlikely(x) static_cast<bool>(__builtin_expect(static_cast<bool>(x), 0)) + +#define MONGO_COMPILER_UNREACHABLE __builtin_unreachable() diff --git a/src/mongo/platform/compiler_msvc.h b/src/mongo/platform/compiler_msvc.h index fb4ab560f24..4a029fe40ed 100644 --- a/src/mongo/platform/compiler_msvc.h +++ b/src/mongo/platform/compiler_msvc.h @@ -56,3 +56,5 @@ #define MONGO_likely(x) bool(x) #define MONGO_unlikely(x) bool(x) + +#define MONGO_COMPILER_UNREACHABLE __assume(0) |