Commit a83ba29c authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Enable -Wunreachable-code

Summary:
Because it finds dead code.
This also removes the dead code found.

Reviewed By: yfeldblum

Differential Revision: D4310312

fbshipit-source-id: 8178dacc9268e1001efc5f803a35ef49e23d692a
parent d7d91eb1
...@@ -139,41 +139,6 @@ meanVariance(const double * begin, const double *const end) { ...@@ -139,41 +139,6 @@ meanVariance(const double * begin, const double *const end) {
return make_pair(sum / n, sqrt((sum2 - sum * sum / n) / n)); return make_pair(sum / n, sqrt((sum2 - sum * sum / n) / n));
} }
/**
* Computes the mode of a sample set through brute force. Assumes
* input is sorted.
*/
static double mode(const double * begin, const double *const end) {
assert(begin < end);
// Lower bound and upper bound for result and their respective
// densities.
auto
result = 0.0,
bestDensity = 0.0;
// Get the variance so we pass it down to density()
auto const sigma = meanVariance(begin, end).second;
if (!sigma) {
// No variance means constant signal
return *begin;
}
FOR_EACH_RANGE (i, begin, end) {
assert(i == begin || *i >= i[-1]);
auto candidate = density(begin, end, *i, sigma * sqrt(2.0));
if (candidate > bestDensity) {
// Found a new best
bestDensity = candidate;
result = *i;
} else {
// Density is decreasing... we could break here if we definitely
// knew this is unimodal.
}
}
return result;
}
/** /**
* Given a bunch of benchmark samples, estimate the actual run time. * Given a bunch of benchmark samples, estimate the actual run time.
*/ */
...@@ -182,55 +147,7 @@ static double estimateTime(double * begin, double * end) { ...@@ -182,55 +147,7 @@ static double estimateTime(double * begin, double * end) {
// Current state of the art: get the minimum. After some // Current state of the art: get the minimum. After some
// experimentation, it seems taking the minimum is the best. // experimentation, it seems taking the minimum is the best.
return *min_element(begin, end); return *min_element(begin, end);
// What follows after estimates the time as the mode of the
// distribution.
// Select the awesomest (i.e. most frequent) result. We do this by
// sorting and then computing the longest run length.
sort(begin, end);
// Eliminate outliers. A time much larger than the minimum time is
// considered an outlier.
while (end[-1] > 2.0 * *begin) {
--end;
if (begin == end) {
LOG(INFO) << *begin;
}
assert(begin < end);
}
double result = 0;
/* Code used just for comparison purposes */ {
unsigned bestFrequency = 0;
unsigned candidateFrequency = 1;
double candidateValue = *begin;
for (auto current = begin + 1; ; ++current) {
if (current == end || *current != candidateValue) {
// Done with the current run, see if it was best
if (candidateFrequency > bestFrequency) {
bestFrequency = candidateFrequency;
result = candidateValue;
}
if (current == end) {
break;
}
// Start a new run
candidateValue = *current;
candidateFrequency = 1;
} else {
// Cool, inside a run, increase the frequency
++candidateFrequency;
}
}
}
result = mode(begin, end);
return result;
} }
static double runBenchmarkGetNSPerIteration(const BenchmarkFun& fun, static double runBenchmarkGetNSPerIteration(const BenchmarkFun& fun,
......
...@@ -14,8 +14,10 @@ ...@@ -14,8 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
#include <folly/Hash.h>
#include <folly/dynamic.h> #include <folly/dynamic.h>
#include <folly/Assume.h>
#include <folly/Hash.h>
#include <folly/portability/BitsFunctexcept.h> #include <folly/portability/BitsFunctexcept.h>
namespace folly { namespace folly {
...@@ -277,9 +279,8 @@ std::size_t dynamic::hash() const { ...@@ -277,9 +279,8 @@ std::size_t dynamic::hash() const {
const auto& str = getString(); const auto& str = getString();
return ::folly::hash::fnv32_buf(str.data(), str.size()); return ::folly::hash::fnv32_buf(str.data(), str.size());
} }
default:
CHECK(0); abort();
} }
assume_unreachable();
} }
char const* dynamic::typeName(Type t) { char const* dynamic::typeName(Type t) {
......
...@@ -96,7 +96,6 @@ void DynamicParser::reportError( ...@@ -96,7 +96,6 @@ void DynamicParser::reportError(
break; // Continue parsing break; // Continue parsing
case OnError::THROW: case OnError::THROW:
stack_.throwErrors(); // Package releaseErrors() into an exception. stack_.throwErrors(); // Package releaseErrors() into an exception.
LOG(FATAL) << "Not reached"; // silence lint false positive
default: default:
LOG(FATAL) << "Bad onError_: " << static_cast<int>(onError_); LOG(FATAL) << "Bad onError_: " << static_cast<int>(onError_);
} }
......
...@@ -28,13 +28,12 @@ ...@@ -28,13 +28,12 @@
namespace __cxxabiv1 { namespace __cxxabiv1 {
extern "C" { extern "C" {
void __cxa_throw( [[noreturn]] void __cxa_throw(
void* thrownException, void* thrownException,
std::type_info* type, std::type_info* type,
void (*destructor)(void*)) __attribute__((__noreturn__)); void (*destructor)(void*));
void* __cxa_begin_catch(void* excObj) throw(); void* __cxa_begin_catch(void* excObj) throw();
void __cxa_rethrow(void) __attribute__((__noreturn__)); [[noreturn]] void __cxa_rethrow(void);
void __cxa_rethrow(void);
void __cxa_end_catch(void); void __cxa_end_catch(void);
} }
...@@ -90,17 +89,17 @@ DECLARE_CALLBACK(RethrowException); ...@@ -90,17 +89,17 @@ DECLARE_CALLBACK(RethrowException);
namespace __cxxabiv1 { namespace __cxxabiv1 {
void __cxa_throw(void* thrownException, [[noreturn]] void __cxa_throw(void* thrownException,
std::type_info* type, std::type_info* type,
void (*destructor)(void*)) { void (*destructor)(void*)) {
static auto orig_cxa_throw = static auto orig_cxa_throw =
reinterpret_cast<decltype(&__cxa_throw)>(dlsym(RTLD_NEXT, "__cxa_throw")); reinterpret_cast<decltype(&__cxa_throw)>(dlsym(RTLD_NEXT, "__cxa_throw"));
getCxaThrowCallbacks().invoke(thrownException, type, destructor); getCxaThrowCallbacks().invoke(thrownException, type, destructor);
orig_cxa_throw(thrownException, type, destructor); orig_cxa_throw(thrownException, type, destructor);
__builtin_unreachable(); // orig_cxa_throw never returns __builtin_unreachable();
} }
void __cxa_rethrow() { [[noreturn]] void __cxa_rethrow() {
// __cxa_rethrow leaves the current exception on the caught stack, // __cxa_rethrow leaves the current exception on the caught stack,
// and __cxa_begin_catch recognizes that case. We could do the same, but // and __cxa_begin_catch recognizes that case. We could do the same, but
// we'll implement something simpler (and slower): we pop the exception from // we'll implement something simpler (and slower): we pop the exception from
...@@ -110,7 +109,7 @@ void __cxa_rethrow() { ...@@ -110,7 +109,7 @@ void __cxa_rethrow() {
dlsym(RTLD_NEXT, "__cxa_rethrow")); dlsym(RTLD_NEXT, "__cxa_rethrow"));
getCxaRethrowCallbacks().invoke(); getCxaRethrowCallbacks().invoke();
orig_cxa_rethrow(); orig_cxa_rethrow();
__builtin_unreachable(); // orig_cxa_rethrow never returns __builtin_unreachable();
} }
void* __cxa_begin_catch(void* excObj) throw() { void* __cxa_begin_catch(void* excObj) throw() {
...@@ -143,7 +142,10 @@ void rethrow_exception(std::exception_ptr ep) { ...@@ -143,7 +142,10 @@ void rethrow_exception(std::exception_ptr ep) {
"_ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE")); "_ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE"));
getRethrowExceptionCallbacks().invoke(ep); getRethrowExceptionCallbacks().invoke(ep);
orig_rethrow_exception(ep); orig_rethrow_exception(ep);
__builtin_unreachable(); // orig_rethrow_exception never returns // Clang knows this is unreachable, but GCC doesn't.
#ifndef __clang__
__builtin_unreachable();
#endif
} }
} // namespace std } // namespace std
...@@ -1963,7 +1963,7 @@ TEST(FiberManager, ABD_DispatcherDestroyedBeforeCallingCommit) { ...@@ -1963,7 +1963,7 @@ TEST(FiberManager, ABD_DispatcherDestroyedBeforeCallingCommit) {
dispatchJobs(executor, jobs, results); dispatchJobs(executor, jobs, results);
throw std::runtime_error( throw std::runtime_error(
"Unexpected exception in user code before commit called"); "Unexpected exception in user code before commit called");
atomicBatchDispatcher.commit(); // atomicBatchDispatcher.commit();
} catch (...) { } catch (...) {
/* User code handles the exception and does not exit process */ /* User code handles the exception and does not exit process */
} }
......
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