Commit 6d9473d8 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 5

Add folly::assume_unreachable

Summary: So that the `[[noreturn]]` attribute can be applied.

Reviewed By: yfeldblum

Differential Revision: D3614122

fbshipit-source-id: 4b95cb553e85c85c277c00b8165671dcc75afac8
parent 9982d892
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#pragma once #pragma once
#include <cstdlib>
#include <folly/Portability.h> #include <folly/Portability.h>
#include <glog/logging.h> #include <glog/logging.h>
...@@ -45,4 +47,18 @@ FOLLY_ALWAYS_INLINE void assume(bool cond) { ...@@ -45,4 +47,18 @@ FOLLY_ALWAYS_INLINE void assume(bool cond) {
#endif #endif
} }
[[noreturn]] FOLLY_ALWAYS_INLINE void assume_unreachable() {
assume(false);
// Do a bit more to get the compiler to understand
// that this function really will never return.
#if defined(__GNUC__)
__builtin_unreachable();
#elif defined(_MSC_VER)
__assume(0);
#else
// Well, it's better than nothing.
std::abort();
#endif
}
} // namespace folly } // namespace folly
...@@ -681,7 +681,7 @@ void* atomicHashArrayInsertRaceThread(void* /* j */) { ...@@ -681,7 +681,7 @@ void* atomicHashArrayInsertRaceThread(void* /* j */) {
} }
} }
pthread_exit((void *) numInserted); pthread_exit((void *) numInserted);
folly::assume(false); folly::assume_unreachable();
} }
TEST(Ahm, atomic_hash_array_insert_race) { TEST(Ahm, atomic_hash_array_insert_race) {
AHA* arr = atomicHashArrayInsertRaceArray.get(); AHA* arr = atomicHashArrayInsertRaceArray.get();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment