[libc-commits] [libc] [libc] Add -Werror for libc tests (PR #160413)

Vinay Deshmukh via libc-commits libc-commits at lists.llvm.org
Sat Sep 27 18:21:02 PDT 2025


https://github.com/vinay-deshmukh updated https://github.com/llvm/llvm-project/pull/160413

>From 9576513f202177c8733c6cb9fe82c9df5f88ad29 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <vinay_deshmukh at outlook.com>
Date: Tue, 23 Sep 2025 19:48:33 -0400
Subject: [PATCH 1/5] -Werror

---
 libc/cmake/modules/LLVMLibCTestRules.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 19da0ad29cd84..34abc0a58f8cd 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -43,7 +43,7 @@ function(_get_common_test_compile_options output_var c_test flags)
     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")
+      list(APPEND compile_options "-Werror")
     endif()
     list(APPEND compile_options "-Wconversion")
     # FIXME: convert to -Wsign-conversion

>From 26fe540482a2247518492ee1ca3a47721d25b897 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <vinay_deshmukh at outlook.com>
Date: Sat, 27 Sep 2025 20:37:45 -0400
Subject: [PATCH 2/5] error: implicit conversion loses integer precision:
 'unsigned long' to 'int' [-Werror,-Wshorten-64-to-32]

---
 libc/test/src/stdio/fileop_test.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/stdio/fileop_test.cpp b/libc/test/src/stdio/fileop_test.cpp
index 02328042b92b3..da9a062e83bf2 100644
--- a/libc/test/src/stdio/fileop_test.cpp
+++ b/libc/test/src/stdio/fileop_test.cpp
@@ -100,7 +100,7 @@ TEST_F(LlvmLibcFILETest, SimpleFileOperations) {
   ASSERT_EQ(LIBC_NAMESPACE::ferror(file), 0);
 
   // This is not a readable file.
-  ASSERT_THAT(LIBC_NAMESPACE::fread(data, 1, 1, file),
+  ASSERT_THAT((int)LIBC_NAMESPACE::fread(data, 1, 1, file),
               returns(EQ(0)).with_errno(NE(0)));
 
   ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));

>From cd4adf58fbd2313f0627221026c889c7cd7f0093 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <vinay_deshmukh at outlook.com>
Date: Sat, 27 Sep 2025 21:12:04 -0400
Subject: [PATCH 3/5] error: implicit conversion loses integer precision:
 'unsigned long' to 'int' [-Werror,-Wshorten-64-to-32]

---
 libc/test/src/stdio/fileop_test.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libc/test/src/stdio/fileop_test.cpp b/libc/test/src/stdio/fileop_test.cpp
index da9a062e83bf2..ed4ba26ed8734 100644
--- a/libc/test/src/stdio/fileop_test.cpp
+++ b/libc/test/src/stdio/fileop_test.cpp
@@ -100,8 +100,8 @@ TEST_F(LlvmLibcFILETest, SimpleFileOperations) {
   ASSERT_EQ(LIBC_NAMESPACE::ferror(file), 0);
 
   // This is not a readable file.
-  ASSERT_THAT((int)LIBC_NAMESPACE::fread(data, 1, 1, file),
-              returns(EQ(0)).with_errno(NE(0)));
+  ASSERT_THAT(LIBC_NAMESPACE::fread(data, 1, 1, file),
+              returns(EQ(size_t(0))).with_errno(NE(0)));
 
   ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
 
@@ -175,7 +175,7 @@ TEST_F(LlvmLibcFILETest, FOpenFWriteSizeGreaterThanOne) {
   // Trying to read more should fetch nothing.
   ASSERT_THAT(
       LIBC_NAMESPACE::fread(read_data, sizeof(MyStruct), WRITE_NMEMB, file),
-      returns(EQ(0)).with_errno(EQ(0)));
+      returns(EQ(size_t(0))).with_errno(EQ(0)));
   EXPECT_NE(LIBC_NAMESPACE::feof(file), 0);
   EXPECT_EQ(LIBC_NAMESPACE::ferror(file), 0);
   ASSERT_EQ(LIBC_NAMESPACE::fclose(file), 0);

>From 69d35e29046580dee570cb3e297da7703d029c33 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <vinay_deshmukh at outlook.com>
Date: Sat, 27 Sep 2025 21:14:02 -0400
Subject: [PATCH 4/5] error: unused parameter 'y_start'
 [-Werror,-Wunused-parameter]

---
 libc/test/src/math/exhaustive/bfloat16_sub_test.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp b/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp
index 11bc6f59dd294..c3d0d5c3ba4cd 100644
--- a/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp
+++ b/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp
@@ -23,7 +23,7 @@ struct Bfloat16SubChecker : public virtual LIBC_NAMESPACE::testing::Test {
   using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>;
   using StorageType = typename FPBits::StorageType;
 
-  uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start,
+  uint64_t check(uint16_t x_start, uint16_t x_stop, [[maybe_unused]] uint16_t y_start,
                  uint16_t y_stop, mpfr::RoundingMode rounding) {
     mpfr::ForceRoundingMode r(rounding);
     if (!r.success)

>From 96bcb9fcd9bc14e7c18abf236d66a469e422564c Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <vinay_deshmukh at outlook.com>
Date: Sat, 27 Sep 2025 21:20:41 -0400
Subject: [PATCH 5/5] error: unused parameter 'y_start'
 [-Werror,-Wunused-parameter]

---
 libc/test/src/math/exhaustive/bfloat16_add_test.cpp | 2 +-
 libc/test/src/math/exhaustive/bfloat16_div_test.cpp | 2 +-
 libc/test/src/math/exhaustive/bfloat16_mul_test.cpp | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libc/test/src/math/exhaustive/bfloat16_add_test.cpp b/libc/test/src/math/exhaustive/bfloat16_add_test.cpp
index 3f4c77978a93d..ff942196dccb5 100644
--- a/libc/test/src/math/exhaustive/bfloat16_add_test.cpp
+++ b/libc/test/src/math/exhaustive/bfloat16_add_test.cpp
@@ -23,7 +23,7 @@ struct Bfloat16AddChecker : public virtual LIBC_NAMESPACE::testing::Test {
   using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>;
   using StorageType = typename FPBits::StorageType;
 
-  uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start,
+  uint64_t check(uint16_t x_start, uint16_t x_stop, [[maybe_unused]] uint16_t y_start,
                  uint16_t y_stop, mpfr::RoundingMode rounding) {
     mpfr::ForceRoundingMode r(rounding);
     if (!r.success)
diff --git a/libc/test/src/math/exhaustive/bfloat16_div_test.cpp b/libc/test/src/math/exhaustive/bfloat16_div_test.cpp
index 2648d5f775af5..48750e40d5f61 100644
--- a/libc/test/src/math/exhaustive/bfloat16_div_test.cpp
+++ b/libc/test/src/math/exhaustive/bfloat16_div_test.cpp
@@ -23,7 +23,7 @@ struct Bfloat16DivChecker : public virtual LIBC_NAMESPACE::testing::Test {
   using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>;
   using StorageType = typename FPBits::StorageType;
 
-  uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start,
+  uint64_t check(uint16_t x_start, uint16_t x_stop, [[maybe_unused]] uint16_t y_start,
                  uint16_t y_stop, mpfr::RoundingMode rounding) {
     mpfr::ForceRoundingMode r(rounding);
     if (!r.success)
diff --git a/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp b/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp
index 3cbbcb500a4fb..ab1d46889a4c6 100644
--- a/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp
+++ b/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp
@@ -23,7 +23,7 @@ struct Bfloat16MulChecker : public virtual LIBC_NAMESPACE::testing::Test {
   using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>;
   using StorageType = typename FPBits::StorageType;
 
-  uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start,
+  uint64_t check(uint16_t x_start, uint16_t x_stop, [[maybe_unused]] uint16_t y_start,
                  uint16_t y_stop, mpfr::RoundingMode rounding) {
     mpfr::ForceRoundingMode r(rounding);
     if (!r.success)



More information about the libc-commits mailing list