Skip to content

Commit 1b2dbf6

Browse files
committed
Change FIREBASE_UNREACHABLE() to use compiler intrinics when available
1 parent 8f1ae72 commit 1b2dbf6

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Firestore/core/src/firebase/firestore/util/firebase_assert.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@
7676
} \
7777
} while (0)
7878

79-
// Assert with custom message that is not compiled out in release builds.
80-
#define FIREBASE_ASSERT_MESSAGE(expression, ...) \
81-
FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(expression, expression, __VA_ARGS__)
82-
8379
// Assert condition is true otherwise display the specified expression,
8480
// message and abort. Compiled out of release builds.
8581
#if defined(NDEBUG)
@@ -106,7 +102,18 @@
106102
// Indicates an area of the code that cannot be reached (except possibly due to
107103
// undefined behaviour or other similar badness). The only reasonable thing to
108104
// do in these cases is to immediately abort.
105+
#if defined(__clang__) || defined(__GNUC__)
106+
// Clang, GCC, (and Intel) compilers have a builtin
107+
#define FIREBASE_UNREACHABLE() __builtin_unreachable()
108+
109+
#elif defined(_WIN32)
110+
// Visual C++ doesn't have a builtin, but assuming an impossible condition has
111+
// the same effect.
112+
#define FIREBASE_UNREACHABLE() __assume(false)
113+
114+
#else
109115
#define FIREBASE_UNREACHABLE() abort()
116+
#endif // defined(__clang__) || defined(__GNUC__)
110117

111118
namespace firebase {
112119
namespace firestore {
@@ -115,7 +122,7 @@ namespace util {
115122
// A no-return helper function. To raise an assertion, use Macro instead.
116123
ABSL_ATTRIBUTE_NORETURN void FailAssert(const char* file,
117124
const char* func,
118-
const int line,
125+
int line,
119126
const char* format,
120127
...);
121128

0 commit comments

Comments
 (0)