[libc-commits] [libc] 8fc87f5 - [libc][NFC] Couple of small warning fixes (#67847)
via libc-commits
libc-commits at lists.llvm.org
Mon Oct 2 16:29:31 PDT 2023
Author: Mikhail R. Gadelha
Date: 2023-10-02T19:29:26-04:00
New Revision: 8fc87f54a8004f0d73f5ce04c8a9f64823d83e80
URL: https://github.com/llvm/llvm-project/commit/8fc87f54a8004f0d73f5ce04c8a9f64823d83e80
DIFF: https://github.com/llvm/llvm-project/commit/8fc87f54a8004f0d73f5ce04c8a9f64823d83e80.diff
LOG: [libc][NFC] Couple of small warning fixes (#67847)
This patch fixes a couple of warnings when compiling with gcc 13:
* CPP/type_traits_test.cpp: 'apply' overrides a member function but is
not marked 'override'
* UnitTest/LibcTest.cpp:98: control reaches end of non-void function
* MPFRWrapper/MPFRUtils.cpp:75: control reaches end of non-void function
* smoke/FrexpTest.h:92: backslash-newline at end of file
* __support/float_to_string.h:118: comparison of unsigned expression in ‘>= 0’ is always true
* test/src/__support/CPP/bitset_test.cpp:197: comparison of unsigned expression in ‘>= 0’ is always true
---------
Signed-off-by: Mikhail R. Gadelha <mikhail at igalia.com>
Added:
Modified:
libc/src/__support/float_to_string.h
libc/src/__support/wctype_utils.h
libc/test/UnitTest/LibcTest.cpp
libc/test/src/__support/CPP/bitset_test.cpp
libc/test/src/__support/CPP/type_traits_test.cpp
libc/test/src/math/smoke/FrexpTest.h
libc/utils/MPFRWrapper/MPFRUtils.cpp
Removed:
################################################################################
diff --git a/libc/src/__support/float_to_string.h b/libc/src/__support/float_to_string.h
index 05189e993babbc9..d3fcec7a652faba 100644
--- a/libc/src/__support/float_to_string.h
+++ b/libc/src/__support/float_to_string.h
@@ -115,7 +115,7 @@ namespace internal {
// Returns floor(log_10(2^e)); requires 0 <= e <= 42039.
LIBC_INLINE constexpr uint32_t log10_pow2(const uint64_t e) {
- LIBC_ASSERT(e >= 0 && e <= 42039 &&
+ LIBC_ASSERT(e <= 42039 &&
"Incorrect exponent to perform log10_pow2 approximation.");
// This approximation is based on the float value for log_10(2). It first
// gives an incorrect result for our purposes at 42039 (well beyond the 16383
diff --git a/libc/src/__support/wctype_utils.h b/libc/src/__support/wctype_utils.h
index 2c8eef8a5c0b70c..6d825499a1b0fdb 100644
--- a/libc/src/__support/wctype_utils.h
+++ b/libc/src/__support/wctype_utils.h
@@ -28,6 +28,8 @@ namespace internal {
LIBC_INLINE cpp::optional<int> wctob(wint_t c) {
// This needs to be translated to EOF at the callsite. This is to avoid
// including stdio.h in this file.
+ // The standard states that wint_t may either be an alias of wchar_t or
+ // an alias of an integer type, so we need to keep the c < 0 check.
if (c > 127 || c < 0)
return cpp::nullopt;
return static_cast<int>(c);
diff --git a/libc/test/UnitTest/LibcTest.cpp b/libc/test/UnitTest/LibcTest.cpp
index 2f18d5778e71d84..b01f40f0526461f 100644
--- a/libc/test/UnitTest/LibcTest.cpp
+++ b/libc/test/UnitTest/LibcTest.cpp
@@ -95,6 +95,7 @@ bool test(RunContext *Ctx, TestCond Cond, ValType LHS, ValType RHS,
case TestCond::GE:
return ExplainDifference(LHS >= RHS, "greater than or equal to");
}
+ __builtin_unreachable();
}
} // namespace internal
diff --git a/libc/test/src/__support/CPP/bitset_test.cpp b/libc/test/src/__support/CPP/bitset_test.cpp
index f1d4e4c2f963644..3632e54907ceb4d 100644
--- a/libc/test/src/__support/CPP/bitset_test.cpp
+++ b/libc/test/src/__support/CPP/bitset_test.cpp
@@ -194,7 +194,7 @@ TEST(LlvmLibcBitsetTest, SetRangeTest) {
// Check setting exactly one unit
bitset.set_range(0, 63);
for (size_t j = 0; j < 256; ++j)
- EXPECT_EQ(bitset.test(j), (j >= 0 && j <= 63));
+ EXPECT_EQ(bitset.test(j), j <= 63);
bitset.reset();
// Check ranges across unit boundaries work.
diff --git a/libc/test/src/__support/CPP/type_traits_test.cpp b/libc/test/src/__support/CPP/type_traits_test.cpp
index 0e5f4a1f738b7aa..a2051f380275326 100644
--- a/libc/test/src/__support/CPP/type_traits_test.cpp
+++ b/libc/test/src/__support/CPP/type_traits_test.cpp
@@ -157,7 +157,7 @@ struct A {
struct B : public A {
virtual ~B() {}
- virtual void apply() { state = B_APPLY_CALLED; }
+ virtual void apply() override { state = B_APPLY_CALLED; }
};
void free_function() {}
diff --git a/libc/test/src/math/smoke/FrexpTest.h b/libc/test/src/math/smoke/FrexpTest.h
index 1740770fd6c4787..3ff169091cc9a38 100644
--- a/libc/test/src/math/smoke/FrexpTest.h
+++ b/libc/test/src/math/smoke/FrexpTest.h
@@ -93,4 +93,4 @@ template <typename T> class FrexpTest : public LIBC_NAMESPACE::testing::Test {
using LlvmLibcFrexpTest = FrexpTest<T>; \
TEST_F(LlvmLibcFrexpTest, SpecialNumbers) { testSpecialNumbers(&func); } \
TEST_F(LlvmLibcFrexpTest, PowersOfTwo) { testPowersOfTwo(&func); } \
- TEST_F(LlvmLibcFrexpTest, SomeIntegers) { testSomeIntegers(&func); }\
+ TEST_F(LlvmLibcFrexpTest, SomeIntegers) { testSomeIntegers(&func); }
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index e23a3c2034cb283..0818955f14de7d3 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -72,6 +72,7 @@ static inline mpfr_rnd_t get_mpfr_rounding_mode(RoundingMode mode) {
return MPFR_RNDN;
break;
}
+ __builtin_unreachable();
}
class MPFRNumber {
More information about the libc-commits
mailing list