Fix 2 new sets of clang compiler warnings.
Fix issues that are flagged by -Wfloat-equal and -Wmissing-noreturn.
In the case of -Wfloat-equal the current cases in regular code are deliberate,
so the change is to silence the warning. For gtest code the appropriate fix is
to switch from EXPECT_EQ to EXPECT_(FLOAT|DOUBLE)_EQ.
The -Wmissing-noreturn warning isn't enabled due to a missing noreturn in
gtest. This issue has been reported to gtest.
Change-Id: Id84c70c21c542716c9ee0c41492e8ff8788c4ef8
diff --git a/runtime/base/histogram-inl.h b/runtime/base/histogram-inl.h
index 4c18ce4..b329a31 100644
--- a/runtime/base/histogram-inl.h
+++ b/runtime/base/histogram-inl.h
@@ -195,6 +195,11 @@
DCHECK_LE(std::abs(out_data->perc_.back() - 1.0), 0.001);
}
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wfloat-equal"
+#endif
+
template <class Value>
inline double Histogram<Value>::Percentile(double per, const CumulativeData& data) const {
DCHECK_GT(data.perc_.size(), 0ull);
@@ -235,6 +240,10 @@
return value;
}
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
} // namespace art
#endif // ART_RUNTIME_BASE_HISTOGRAM_INL_H_
diff --git a/runtime/base/histogram_test.cc b/runtime/base/histogram_test.cc
index 454f2ab..7aa5f90 100644
--- a/runtime/base/histogram_test.cc
+++ b/runtime/base/histogram_test.cc
@@ -41,14 +41,14 @@
hist->AddValue(static_cast<uint64_t>(50));
}
mean = hist->Mean();
- EXPECT_EQ(mean, 50);
+ EXPECT_DOUBLE_EQ(mean, 50.0);
hist->Reset();
hist->AddValue(9);
hist->AddValue(17);
hist->AddValue(28);
hist->AddValue(28);
mean = hist->Mean();
- EXPECT_EQ(20.5, mean);
+ EXPECT_DOUBLE_EQ(20.5, mean);
}
TEST(Histtest, VarianceTest) {
@@ -60,7 +60,7 @@
hist->AddValue(28);
hist->AddValue(28);
variance = hist->Variance();
- EXPECT_EQ(64.25, variance);
+ EXPECT_DOUBLE_EQ(64.25, variance);
}
TEST(Histtest, Percentile) {
@@ -236,7 +236,7 @@
}
hist->CreateHistogram(&data);
per_995 = hist->Percentile(0.995, data);
- EXPECT_EQ(per_995, 0);
+ EXPECT_DOUBLE_EQ(per_995, 0.0);
hist->Reset();
for (size_t idx = 0; idx < 200; idx++) {
for (uint64_t val = 1ull; val <= 4ull; val++) {
@@ -246,8 +246,8 @@
hist->CreateHistogram(&data);
per_005 = hist->Percentile(0.005, data);
per_995 = hist->Percentile(0.995, data);
- EXPECT_EQ(1, per_005);
- EXPECT_EQ(4, per_995);
+ EXPECT_DOUBLE_EQ(1.0, per_005);
+ EXPECT_DOUBLE_EQ(4.0, per_995);
}
TEST(Histtest, SpikyValues) {
diff --git a/runtime/base/macros.h b/runtime/base/macros.h
index f5a38bb..bbe0f5a 100644
--- a/runtime/base/macros.h
+++ b/runtime/base/macros.h
@@ -177,6 +177,7 @@
#define PURE __attribute__ ((__pure__))
#define WARN_UNUSED __attribute__((warn_unused_result))
+#define NO_RETURN __attribute__((noreturn))
template<typename T> void UNUSED(const T&) {}
#define UNREACHABLE __builtin_unreachable