Commit ce7d3124 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: D4342893

fbshipit-source-id: e500734ff5927320b2356106d10016e298d67393
parent 8d7ec4c6
......@@ -105,75 +105,6 @@ void detail::addBenchmarkImpl(const char* file, const char* name,
benchmarks().emplace_back(file, name, std::move(fun));
}
/**
* Given a point, gives density at that point as a number 0.0 < x <=
* 1.0. The result is 1.0 if all samples are equal to where, and
* decreases near 0 if all points are far away from it. The density is
* computed with the help of a radial basis function.
*/
static double density(const double * begin, const double *const end,
const double where, const double bandwidth) {
assert(begin < end);
assert(bandwidth > 0.0);
double sum = 0.0;
FOR_EACH_RANGE (i, begin, end) {
auto d = (*i - where) / bandwidth;
sum += exp(- d * d);
}
return sum / (end - begin);
}
/**
* Computes mean and variance for a bunch of data points. Note that
* mean is currently not being used.
*/
static pair<double, double>
meanVariance(const double * begin, const double *const end) {
assert(begin < end);
double sum = 0.0, sum2 = 0.0;
FOR_EACH_RANGE (i, begin, end) {
sum += *i;
sum2 += *i * *i;
}
auto const n = end - begin;
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.
*/
......@@ -182,55 +113,7 @@ static double estimateTime(double * begin, double * end) {
// Current state of the art: get the minimum. After some
// experimentation, it seems taking the minimum is the best.
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,
......
......@@ -14,8 +14,10 @@
* limitations under the License.
*/
#include <folly/Hash.h>
#include <folly/dynamic.h>
#include <folly/Assume.h>
#include <folly/Hash.h>
#include <folly/portability/BitsFunctexcept.h>
namespace folly {
......@@ -277,9 +279,8 @@ std::size_t dynamic::hash() const {
const auto& str = getString();
return ::folly::hash::fnv32_buf(str.data(), str.size());
}
default:
CHECK(0); abort();
}
assume_unreachable();
}
char const* dynamic::typeName(Type t) {
......
......@@ -96,7 +96,6 @@ void DynamicParser::reportError(
break; // Continue parsing
case OnError::THROW:
stack_.throwErrors(); // Package releaseErrors() into an exception.
LOG(FATAL) << "Not reached"; // silence lint false positive
default:
LOG(FATAL) << "Bad onError_: " << static_cast<int>(onError_);
}
......
......@@ -34,7 +34,6 @@ void __cxa_throw(
void (*destructor)(void*)) __attribute__((__noreturn__));
void* __cxa_begin_catch(void* excObj) throw();
void __cxa_rethrow(void) __attribute__((__noreturn__));
void __cxa_rethrow(void);
void __cxa_end_catch(void);
}
......@@ -88,6 +87,15 @@ DECLARE_CALLBACK(RethrowException);
} // exception_tracer
} // folly
// Clang is smart enough to understand that the symbols we're loading
// are [[noreturn]], but GCC is not. In order to be able to build with
// -Wunreachable-code enable for Clang, these __builtin_unreachable()
// calls need to go away. Everything else is messy though, so just
// #define it to an empty macro under Clang and be done with it.
#ifdef __clang__
# define __builtin_unreachable()
#endif
namespace __cxxabiv1 {
void __cxa_throw(void* thrownException,
......
......@@ -1964,7 +1964,7 @@ TEST(FiberManager, ABD_DispatcherDestroyedBeforeCallingCommit) {
dispatchJobs(executor, jobs, results);
throw std::runtime_error(
"Unexpected exception in user code before commit called");
atomicBatchDispatcher.commit();
// atomicBatchDispatcher.commit();
} catch (...) {
/* 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