[libc-commits] [libc] [libc]: Add -Wextra for libc tests (PR #133643)

Vinay Deshmukh via libc-commits libc-commits at lists.llvm.org
Sun Mar 30 12:48:01 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 1/4] 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 2/4] 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 3/4] 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 4/4] 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();
 }



More information about the libc-commits mailing list