[libc-commits] [libc] [libc]: Add -Wextra for libc tests (PR #133643)
Vinay Deshmukh via libc-commits
libc-commits at lists.llvm.org
Tue Apr 1 18:09:26 PDT 2025
https://github.com/vinay-deshmukh updated https://github.com/llvm/llvm-project/pull/133643
>From ef115eeb591c6a5915d878b6a233224f3e0b1e14 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sun, 30 Mar 2025 13:15:10 -0400
Subject: [PATCH 01/13] Wextra
---
libc/CMakeLists.txt | 1 +
libc/cmake/modules/LLVMLibCTestRules.cmake | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index b264dcb4974c7..0bfb7b8aad20d 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -34,6 +34,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions("-D_DEBUG")
endif()
+add_compile_options("-Werror=extra")
# Default to C++17
set(CMAKE_CXX_STANDARD 17)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 0f0d612d04ba5..99386e89847ea 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -31,7 +31,7 @@ function(_get_common_test_compile_options output_var c_test flags)
endif()
# list(APPEND compile_options "-Wall")
- # list(APPEND compile_options "-Wextra")
+ list(APPEND compile_options "-Wextra")
# -DLIBC_WNO_ERROR=ON if you can't build cleanly with -Werror.
if(NOT LIBC_WNO_ERROR)
# list(APPEND compile_options "-Werror")
>From 555a99f80c490140e55354612950212be5218571 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sun, 30 Mar 2025 14:57:24 -0400
Subject: [PATCH 02/13] unused
---
libc/test/UnitTest/LibcTest.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h
index fbeafd0bacb75..b65271dd84b4a 100644
--- a/libc/test/UnitTest/LibcTest.h
+++ b/libc/test/UnitTest/LibcTest.h
@@ -81,7 +81,7 @@ struct Message {
// A trivial object to catch the Message, this enables custom logging and
// returning from the test function, see LIBC_TEST_SCAFFOLDING_ below.
struct Failure {
- void operator=(Message msg) {}
+ void operator=(Message /*msg*/) {}
};
struct RunContext {
>From 21530d53cb9811f462e11ee4cf8ccfed85ba7a5c Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sun, 30 Mar 2025 15:09:55 -0400
Subject: [PATCH 03/13] unused
---
libc/test/UnitTest/LibcDeathTestExecutors.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/UnitTest/LibcDeathTestExecutors.cpp b/libc/test/UnitTest/LibcDeathTestExecutors.cpp
index 943e2c23c5fde..f2b048864b556 100644
--- a/libc/test/UnitTest/LibcDeathTestExecutors.cpp
+++ b/libc/test/UnitTest/LibcDeathTestExecutors.cpp
@@ -22,7 +22,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace testing {
bool Test::testProcessKilled(testutils::FunctionCaller *Func, int Signal,
- const char *LHSStr, const char *RHSStr,
+ const char *LHSStr, const char * /*RHSStr*/,
internal::Location Loc) {
testutils::ProcessStatus Result =
testutils::invoke_in_subprocess(Func, TIMEOUT_MS);
>From 283dac9b1ee35d2275f967984f0b1807020c0ca1 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sun, 30 Mar 2025 15:47:39 -0400
Subject: [PATCH 04/13] unused
---
libc/test/UnitTest/HermeticTestUtils.cpp | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index a9494af746d52..54be9e92bf10b 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -29,7 +29,7 @@ int atexit(void (*func)(void));
// add_libc_hermetic_test properly. Such that they won't get correct linkage
// against the object containing this function. We create a dummy function that
// always returns 0 to indicate a failure.
-[[gnu::weak]] unsigned long getauxval(unsigned long id) { return 0; }
+[[gnu::weak]] unsigned long getauxval(unsigned long /*id*/) { return 0; }
} // namespace LIBC_NAMESPACE_DECL
@@ -124,7 +124,7 @@ unsigned long __getauxval(unsigned long id) {
} // extern "C"
-void *operator new(size_t size, void *ptr) { return ptr; }
+void *operator new(size_t /*size*/, void *ptr) { return ptr; }
void *operator new(size_t size) { return malloc(size); }
@@ -136,7 +136,7 @@ void operator delete(void *) {
__builtin_trap();
}
-void operator delete(void *ptr, size_t size) { __builtin_trap(); }
+void operator delete(void * /*ptr*/, size_t /*size*/) { __builtin_trap(); }
// Defining members in the std namespace is not preferred. But, we do it here
// so that we can use it to define the operator new which takes std::align_val_t
@@ -145,8 +145,10 @@ namespace std {
enum class align_val_t : size_t {};
} // namespace std
-void operator delete(void *mem, std::align_val_t) noexcept { __builtin_trap(); }
+void operator delete(void * /*mem*/, std::align_val_t) noexcept {
+ __builtin_trap();
+}
-void operator delete(void *mem, unsigned int, std::align_val_t) noexcept {
+void operator delete(void * /*mem*/, unsigned int, std::align_val_t) noexcept {
__builtin_trap();
}
>From 05ef005b91a98f754ff16578a8fc1a4bdccf5939 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sun, 30 Mar 2025 15:56:40 -0400
Subject: [PATCH 05/13] unused
---
libc/test/src/__support/CPP/integer_sequence_test.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/test/src/__support/CPP/integer_sequence_test.cpp b/libc/test/src/__support/CPP/integer_sequence_test.cpp
index fe378522b446b..56e75f496255f 100644
--- a/libc/test/src/__support/CPP/integer_sequence_test.cpp
+++ b/libc/test/src/__support/CPP/integer_sequence_test.cpp
@@ -23,7 +23,8 @@ TEST(LlvmLibcIntegerSequencetTest, Basic) {
(is_same_v<ULLSeq, make_integer_sequence<unsigned long long, 4>>));
}
-template <typename T, T... Ts> bool checkArray(integer_sequence<T, Ts...> seq) {
+template <typename T, T... Ts>
+bool checkArray(integer_sequence<T, Ts...> /*seq*/) {
T arr[sizeof...(Ts)]{Ts...};
for (T i = 0; i < static_cast<T>(sizeof...(Ts)); i++)
>From cf7aeba5dae2f53f02a84acbb40cfca57bcb0bbd Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Tue, 1 Apr 2025 20:15:25 -0400
Subject: [PATCH 06/13] unused
---
libc/test/UnitTest/FPExceptMatcher.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/UnitTest/FPExceptMatcher.h b/libc/test/UnitTest/FPExceptMatcher.h
index 978501df7e3ed..50ebdbd0ce204 100644
--- a/libc/test/UnitTest/FPExceptMatcher.h
+++ b/libc/test/UnitTest/FPExceptMatcher.h
@@ -43,7 +43,7 @@ class FPExceptMatcher : public Matcher<bool> {
// Takes ownership of func.
explicit FPExceptMatcher(FunctionCaller *func);
- bool match(bool unused) { return exceptionRaised; }
+ bool match(bool /*unused*/) { return exceptionRaised; }
void explainError() override {
tlog << "A floating point exception should have been raised but it "
>From bf8471d65c6b2b1ac61d9b4966d1a2be0ef723e8 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Tue, 1 Apr 2025 20:16:29 -0400
Subject: [PATCH 07/13] unused
---
libc/test/UnitTest/FPExceptMatcher.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/UnitTest/FPExceptMatcher.cpp b/libc/test/UnitTest/FPExceptMatcher.cpp
index d66066023984e..868c5f8e27dbc 100644
--- a/libc/test/UnitTest/FPExceptMatcher.cpp
+++ b/libc/test/UnitTest/FPExceptMatcher.cpp
@@ -31,7 +31,7 @@ namespace testing {
static thread_local sigjmp_buf jumpBuffer;
static thread_local bool caughtExcept;
-static void sigfpeHandler(int sig) {
+static void sigfpeHandler(int /*sig*/) {
caughtExcept = true;
siglongjmp(jumpBuffer, -1);
}
>From 6244b9f6b013ad0c0f76bbdf22eabda4ab04d377 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Tue, 1 Apr 2025 20:32:07 -0400
Subject: [PATCH 08/13] [[maybe_unused]]
---
libc/test/src/__support/freelist_heap_test.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/src/__support/freelist_heap_test.cpp b/libc/test/src/__support/freelist_heap_test.cpp
index 0623272dd5b9f..be6bb25e96e4a 100644
--- a/libc/test/src/__support/freelist_heap_test.cpp
+++ b/libc/test/src/__support/freelist_heap_test.cpp
@@ -48,7 +48,7 @@ using LIBC_NAMESPACE::cpp::span;
RunTest(*freelist_heap, freelist_heap->region().size()); \
} \
void LlvmLibcFreeListHeapTest##TestCase::RunTest(FreeListHeap &allocator, \
- size_t N)
+ [[maybe_unused]] size_t N)
TEST_FOR_EACH_ALLOCATOR(CanAllocate, 2048) {
constexpr size_t ALLOC_SIZE = 512;
>From 7ae6b90bddeb704ea6a69d93d9129764cfdd9ec7 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Tue, 1 Apr 2025 20:40:35 -0400
Subject: [PATCH 09/13] unused
---
libc/utils/MPFRWrapper/MPFRUtils.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h
index bc65f87c6b5ab..e8f253afad3ba 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.h
+++ b/libc/utils/MPFRWrapper/MPFRUtils.h
@@ -352,7 +352,7 @@ template <Operation op, typename InputType, typename OutputType>
__attribute__((no_sanitize("address"))) cpp::enable_if_t<
is_valid_operation<op, InputType, OutputType>(),
internal::MPFRMatcher<op, /*is_silent*/ false, InputType, OutputType>>
-get_mpfr_matcher(InputType input, OutputType output_unused,
+get_mpfr_matcher(InputType input, OutputType /*output_unused*/,
double ulp_tolerance, RoundingMode rounding) {
return internal::MPFRMatcher<op, /*is_silent*/ false, InputType, OutputType>(
input, ulp_tolerance, rounding);
@@ -362,7 +362,7 @@ template <Operation op, typename InputType, typename OutputType>
__attribute__((no_sanitize("address"))) cpp::enable_if_t<
is_valid_operation<op, InputType, OutputType>(),
internal::MPFRMatcher<op, /*is_silent*/ true, InputType, OutputType>>
-get_silent_mpfr_matcher(InputType input, OutputType output_unused,
+get_silent_mpfr_matcher(InputType input, OutputType /*output_unused*/,
double ulp_tolerance, RoundingMode rounding) {
return internal::MPFRMatcher<op, /*is_silent*/ true, InputType, OutputType>(
input, ulp_tolerance, rounding);
>From 6447e76209ff68826bcd75a8aaaaf625eb968402 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Tue, 1 Apr 2025 20:46:36 -0400
Subject: [PATCH 10/13] unused
---
libc/test/src/string/memory_utils/op_tests.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/libc/test/src/string/memory_utils/op_tests.cpp b/libc/test/src/string/memory_utils/op_tests.cpp
index 2057ab3eaaded..26d1350a36f22 100644
--- a/libc/test/src/string/memory_utils/op_tests.cpp
+++ b/libc/test/src/string/memory_utils/op_tests.cpp
@@ -72,7 +72,8 @@ void CopyAdaptor(cpp::span<char> dst, cpp::span<char> src, size_t size) {
FnImpl(as_byte(dst), as_byte(src), size);
}
template <size_t Size, auto FnImpl>
-void CopyBlockAdaptor(cpp::span<char> dst, cpp::span<char> src, size_t size) {
+void CopyBlockAdaptor(cpp::span<char> dst, cpp::span<char> src,
+ size_t /*size*/) {
FnImpl(as_byte(dst), as_byte(src));
}
@@ -153,7 +154,7 @@ void SetAdaptor(cpp::span<char> dst, uint8_t value, size_t size) {
FnImpl(as_byte(dst), value, size);
}
template <size_t Size, auto FnImpl>
-void SetBlockAdaptor(cpp::span<char> dst, uint8_t value, size_t size) {
+void SetBlockAdaptor(cpp::span<char> dst, uint8_t value, size_t /*size*/) {
FnImpl(as_byte(dst), value);
}
@@ -242,7 +243,7 @@ int CmpAdaptor(cpp::span<char> p1, cpp::span<char> p2, size_t size) {
return (int)FnImpl(as_byte(p1), as_byte(p2), size);
}
template <size_t Size, auto FnImpl>
-int CmpBlockAdaptor(cpp::span<char> p1, cpp::span<char> p2, size_t size) {
+int CmpBlockAdaptor(cpp::span<char> p1, cpp::span<char> p2, size_t /*size*/) {
return (int)FnImpl(as_byte(p1), as_byte(p2));
}
>From 3a2968d77ebf75b2f386c4a755544e5f67fd0b0f Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Tue, 1 Apr 2025 20:53:09 -0400
Subject: [PATCH 11/13] unused
---
libc/test/src/strings/bzero_test.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/src/strings/bzero_test.cpp b/libc/test/src/strings/bzero_test.cpp
index 4d4112f4be8ee..e3091556da276 100644
--- a/libc/test/src/strings/bzero_test.cpp
+++ b/libc/test/src/strings/bzero_test.cpp
@@ -14,7 +14,7 @@
namespace LIBC_NAMESPACE_DECL {
// Adapt CheckMemset signature to bzero.
-static inline void Adaptor(cpp::span<char> p1, uint8_t value, size_t size) {
+static inline void Adaptor(cpp::span<char> p1, uint8_t /*value*/, size_t size) {
LIBC_NAMESPACE::bzero(p1.begin(), size);
}
>From a2cd02af5ada16b6ff23e6f94bc7f8f9c1ddbaaf Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Tue, 1 Apr 2025 21:00:18 -0400
Subject: [PATCH 12/13] unused
---
libc/test/src/stdlib/StrfromTest.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/test/src/stdlib/StrfromTest.h b/libc/test/src/stdlib/StrfromTest.h
index 197165c68d587..4a7f0eca80644 100644
--- a/libc/test/src/stdlib/StrfromTest.h
+++ b/libc/test/src/stdlib/StrfromTest.h
@@ -357,7 +357,7 @@ class StrfromTest : public LIBC_NAMESPACE::testing::Test {
ASSERT_STREQ_LEN(written, buff, "1.0e+01");
}
- void floatDecimalExpLongDoublePrec(FunctionT func) {
+ void floatDecimalExpLongDoublePrec(FunctionT /*func*/) {
// Mark as maybe_unused to silence unused variable
// warning when long double is not 80-bit
[[maybe_unused]] char buff[100];
@@ -422,7 +422,7 @@ class StrfromTest : public LIBC_NAMESPACE::testing::Test {
ASSERT_STREQ_LEN(written, buff, "1.2340000000000000814e-10");
}
- void floatDecimalAutoLongDoublePrec(FunctionT func) {
+ void floatDecimalAutoLongDoublePrec(FunctionT /*func*/) {
// Mark as maybe_unused to silence unused variable
// warning when long double is not 80-bit
[[maybe_unused]] char buff[100];
>From 8651a55a7c1014ea3dfff503b643588cd120b854 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Tue, 1 Apr 2025 21:09:01 -0400
Subject: [PATCH 13/13] unused
---
libc/test/include/stdbit_stub.h | 42 ++++++++++++++++-----------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/libc/test/include/stdbit_stub.h b/libc/test/include/stdbit_stub.h
index 3d2e0fb60334e..368133f413a24 100644
--- a/libc/test/include/stdbit_stub.h
+++ b/libc/test/include/stdbit_stub.h
@@ -17,11 +17,11 @@
#include <stdbool.h> // bool in C
#define STDBIT_STUB_FUNCTION(FUNC_NAME, LEADING_VAL) \
- unsigned FUNC_NAME##_uc(unsigned char x) { return LEADING_VAL##AU; } \
- unsigned FUNC_NAME##_us(unsigned short x) { return LEADING_VAL##BU; } \
- unsigned FUNC_NAME##_ui(unsigned int x) { return LEADING_VAL##CU; } \
- unsigned FUNC_NAME##_ul(unsigned long x) { return LEADING_VAL##DU; } \
- unsigned FUNC_NAME##_ull(unsigned long long x) { return LEADING_VAL##EU; }
+ unsigned FUNC_NAME##_uc(unsigned char /*x*/) { return LEADING_VAL##AU; } \
+ unsigned FUNC_NAME##_us(unsigned short /*x*/) { return LEADING_VAL##BU; } \
+ unsigned FUNC_NAME##_ui(unsigned int /*x*/) { return LEADING_VAL##CU; } \
+ unsigned FUNC_NAME##_ul(unsigned long /*x*/) { return LEADING_VAL##DU; } \
+ unsigned FUNC_NAME##_ull(unsigned long long /*x*/) { return LEADING_VAL##EU; }
__BEGIN_C_DECLS
@@ -36,24 +36,24 @@ STDBIT_STUB_FUNCTION(stdc_first_trailing_one, 0x1)
STDBIT_STUB_FUNCTION(stdc_count_zeros, 0x2)
STDBIT_STUB_FUNCTION(stdc_count_ones, 0x3)
-bool stdc_has_single_bit_uc(unsigned char x) { return false; }
-bool stdc_has_single_bit_us(unsigned short x) { return false; }
-bool stdc_has_single_bit_ui(unsigned x) { return false; }
-bool stdc_has_single_bit_ul(unsigned long x) { return false; }
-bool stdc_has_single_bit_ull(unsigned long long x) { return false; }
+bool stdc_has_single_bit_uc(unsigned char /*x*/) { return false; }
+bool stdc_has_single_bit_us(unsigned short /*x*/) { return false; }
+bool stdc_has_single_bit_ui(unsigned /*x*/) { return false; }
+bool stdc_has_single_bit_ul(unsigned long /*x*/) { return false; }
+bool stdc_has_single_bit_ull(unsigned long long /*x*/) { return false; }
STDBIT_STUB_FUNCTION(stdc_bit_width, 0x4)
-unsigned char stdc_bit_floor_uc(unsigned char x) { return 0x5AU; }
-unsigned short stdc_bit_floor_us(unsigned short x) { return 0x5BU; }
-unsigned stdc_bit_floor_ui(unsigned x) { return 0x5CU; }
-unsigned long stdc_bit_floor_ul(unsigned long x) { return 0x5DUL; }
-unsigned long long stdc_bit_floor_ull(unsigned long long x) { return 0x5EULL; }
-
-unsigned char stdc_bit_ceil_uc(unsigned char x) { return 0x6AU; }
-unsigned short stdc_bit_ceil_us(unsigned short x) { return 0x6BU; }
-unsigned stdc_bit_ceil_ui(unsigned x) { return 0x6CU; }
-unsigned long stdc_bit_ceil_ul(unsigned long x) { return 0x6DUL; }
-unsigned long long stdc_bit_ceil_ull(unsigned long long x) { return 0x6EULL; }
+unsigned char stdc_bit_floor_uc(unsigned char /*x*/) { return 0x5AU; }
+unsigned short stdc_bit_floor_us(unsigned short /*x*/) { return 0x5BU; }
+unsigned stdc_bit_floor_ui(unsigned /*x*/) { return 0x5CU; }
+unsigned long stdc_bit_floor_ul(unsigned long /*x*/) { return 0x5DUL; }
+unsigned long long stdc_bit_floor_ull(unsigned long long /*x*/) { return 0x5EULL; }
+
+unsigned char stdc_bit_ceil_uc(unsigned char /*x*/) { return 0x6AU; }
+unsigned short stdc_bit_ceil_us(unsigned short /*x*/) { return 0x6BU; }
+unsigned stdc_bit_ceil_ui(unsigned /*x*/) { return 0x6CU; }
+unsigned long stdc_bit_ceil_ul(unsigned long /*x*/) { return 0x6DUL; }
+unsigned long long stdc_bit_ceil_ull(unsigned long long /*x*/) { return 0x6EULL; }
__END_C_DECLS
More information about the libc-commits
mailing list