From: Christopher Dykes Date: Tue, 26 Jul 2016 22:50:47 +0000 (-0700) Subject: Add folly::assume_unreachable X-Git-Tag: v2016.07.29.00~14 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6d9473d8c3aeddeebc574be309ad2d5d3bb765f7;p=folly.git Add folly::assume_unreachable Summary: So that the `[[noreturn]]` attribute can be applied. Reviewed By: yfeldblum Differential Revision: D3614122 fbshipit-source-id: 4b95cb553e85c85c277c00b8165671dcc75afac8 --- diff --git a/folly/Assume.h b/folly/Assume.h index 8f807433..c4d8fabb 100644 --- a/folly/Assume.h +++ b/folly/Assume.h @@ -16,6 +16,8 @@ #pragma once +#include + #include #include @@ -45,4 +47,18 @@ FOLLY_ALWAYS_INLINE void assume(bool cond) { #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 diff --git a/folly/test/AtomicHashMapTest.cpp b/folly/test/AtomicHashMapTest.cpp index e62e8386..28f57678 100644 --- a/folly/test/AtomicHashMapTest.cpp +++ b/folly/test/AtomicHashMapTest.cpp @@ -681,7 +681,7 @@ void* atomicHashArrayInsertRaceThread(void* /* j */) { } } pthread_exit((void *) numInserted); - folly::assume(false); + folly::assume_unreachable(); } TEST(Ahm, atomic_hash_array_insert_race) { AHA* arr = atomicHashArrayInsertRaceArray.get();