Improve BENCHMARK_UNREACHABLE() implementation.

This patch primarily changes the BENCHMARK_UNREACHABLE()
implementation under MSVC to use __assume(false) instead
of being a NORETURN function, which ironically caused
unreachable code warnings.

Second, since the NOTHROW function attempt generated the
warnings we meant to avoid, it has been replaced with a dummy
null statement.
This commit is contained in:
Eric Fiselier 2017-11-26 13:55:37 -07:00
parent 11dc36822b
commit 2ec7399cf1
2 changed files with 3 additions and 16 deletions

View File

@ -108,14 +108,6 @@ namespace internal {
void UseCharPointer(char const volatile*) {}
#ifdef BENCHMARK_HAS_NO_BUILTIN_UNREACHABLE
BENCHMARK_NORETURN void UnreachableImp(const char* FName, int Line) {
std::cerr << FName << ":" << Line << " executing unreachable code!"
<< std::endl;
std::abort();
}
#endif
class ThreadManager {
public:
ThreadManager(int num_threads)

View File

@ -67,15 +67,10 @@
#if defined(COMPILER_GCC) || __has_builtin(__builtin_unreachable)
#define BENCHMARK_UNREACHABLE() __builtin_unreachable()
#elif defined(COMPILER_MSVC)
#define BENCHMARK_UNREACHABLE() __assume(false)
#else
#define BENCHMARK_HAS_NO_BUILTIN_UNREACHABLE
namespace benchmark {
namespace internal {
BENCHMARK_NORETURN void UnreachableImp(const char* FName, int Line);
}
} // namespace benchmark
#define BENCHMARK_UNREACHABLE() \
::benchmark::internal::UnreachableImp(__FILE__, __LINE__)
#define BENCHMARK_UNREACHABLE() ((void)0)
#endif
#endif // BENCHMARK_INTERNAL_MACROS_H_