Skip to content

Commit 5d6c00c

Browse files
[libc] Add -Werror for libc tests (llvm#160413)
Relates to llvm#119281 Note: 1) As this PR enables `-Werror` for `libc` tests, it's very likely some downstream CI's may fail / start failing, so it's very likely this PR may need to be reverted and re-applied. P.S. I do not have merge permissions, so I will need one of the reviews to merge it for me. Thank you!
1 parent 9a2e825 commit 5d6c00c

File tree

15 files changed

+77
-57
lines changed

15 files changed

+77
-57
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function(_get_common_test_compile_options output_var c_test flags)
3838
list(APPEND compile_options "-Wextra")
3939
# -DLIBC_WNO_ERROR=ON if you can't build cleanly with -Werror.
4040
if(NOT LIBC_WNO_ERROR)
41-
# list(APPEND compile_options "-Werror")
41+
list(APPEND compile_options "-Werror")
4242
endif()
4343
list(APPEND compile_options "-Wconversion")
4444
# FIXME: convert to -Wsign-conversion

libc/test/include/complex_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ TEST(LlvmLibcComplexTest, CMPLXMacro) {
2727
EXPECT_CFP_EQ(CMPLXL(1.0l, 0), 1.0l);
2828

2929
#ifdef LIBC_TYPES_HAS_CFLOAT16
30-
EXPECT_CFP_EQ(CMPLXF16(0, 1.0), I);
31-
EXPECT_CFP_EQ(CMPLXF16(1.0, 0), 1.0);
30+
EXPECT_CFP_EQ(CMPLXF16(0, 1.0), static_cast<_Complex _Float16>(I));
31+
EXPECT_CFP_EQ(CMPLXF16(1.0, 0), static_cast<_Complex _Float16>(1.0));
3232
#endif // LIBC_TYPES_HAS_CFLOAT16
3333

3434
#ifdef LIBC_TYPES_HAS_CFLOAT128

libc/test/integration/src/pthread/pthread_barrier_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
pthread_barrier_t barrier;
2727
LIBC_NAMESPACE::cpp::Atomic<int> counter;
2828

29-
void *increment_counter_and_wait(void *args) {
29+
void *increment_counter_and_wait([[maybe_unused]] void *args) {
3030
counter.fetch_add(1);
3131
return reinterpret_cast<void *>(
3232
LIBC_NAMESPACE::pthread_barrier_wait(&barrier));
@@ -102,7 +102,7 @@ void reused_barrier_test() {
102102
LIBC_NAMESPACE::pthread_barrier_destroy(&barrier);
103103
}
104104

105-
void *barrier_wait(void *in) {
105+
void *barrier_wait([[maybe_unused]] void *in) {
106106
return reinterpret_cast<void *>(
107107
LIBC_NAMESPACE::pthread_barrier_wait(&barrier));
108108
}

libc/test/src/math/exhaustive/bfloat16_add_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ struct Bfloat16AddChecker : public virtual LIBC_NAMESPACE::testing::Test {
2323
using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>;
2424
using StorageType = typename FPBits::StorageType;
2525

26-
uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start,
27-
uint16_t y_stop, mpfr::RoundingMode rounding) {
26+
uint64_t check(uint16_t x_start, uint16_t x_stop,
27+
[[maybe_unused]] uint16_t y_start, uint16_t y_stop,
28+
mpfr::RoundingMode rounding) {
2829
mpfr::ForceRoundingMode r(rounding);
2930
if (!r.success)
3031
return true;

libc/test/src/math/exhaustive/bfloat16_div_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ struct Bfloat16DivChecker : public virtual LIBC_NAMESPACE::testing::Test {
2323
using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>;
2424
using StorageType = typename FPBits::StorageType;
2525

26-
uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start,
27-
uint16_t y_stop, mpfr::RoundingMode rounding) {
26+
uint64_t check(uint16_t x_start, uint16_t x_stop,
27+
[[maybe_unused]] uint16_t y_start, uint16_t y_stop,
28+
mpfr::RoundingMode rounding) {
2829
mpfr::ForceRoundingMode r(rounding);
2930
if (!r.success)
3031
return true;

libc/test/src/math/exhaustive/bfloat16_mul_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ struct Bfloat16MulChecker : public virtual LIBC_NAMESPACE::testing::Test {
2323
using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>;
2424
using StorageType = typename FPBits::StorageType;
2525

26-
uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start,
27-
uint16_t y_stop, mpfr::RoundingMode rounding) {
26+
uint64_t check(uint16_t x_start, uint16_t x_stop,
27+
[[maybe_unused]] uint16_t y_start, uint16_t y_stop,
28+
mpfr::RoundingMode rounding) {
2829
mpfr::ForceRoundingMode r(rounding);
2930
if (!r.success)
3031
return true;

libc/test/src/math/exhaustive/bfloat16_sub_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ struct Bfloat16SubChecker : public virtual LIBC_NAMESPACE::testing::Test {
2323
using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>;
2424
using StorageType = typename FPBits::StorageType;
2525

26-
uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start,
27-
uint16_t y_stop, mpfr::RoundingMode rounding) {
26+
uint64_t check(uint16_t x_start, uint16_t x_stop,
27+
[[maybe_unused]] uint16_t y_start, uint16_t y_stop,
28+
mpfr::RoundingMode rounding) {
2829
mpfr::ForceRoundingMode r(rounding);
2930
if (!r.success)
3031
return true;

libc/test/src/signal/sigaltstack_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void handler(int) {
3333
// out or mapped to a register.
3434
uint8_t var[LOCAL_VAR_SIZE];
3535
for (int i = 0; i < LOCAL_VAR_SIZE; ++i)
36-
var[i] = i;
36+
var[i] = static_cast<uint8_t>(i);
3737
// Verify that array is completely on the alt_stack.
3838
for (int i = 0; i < LOCAL_VAR_SIZE; ++i) {
3939
if (!(uintptr_t(var + i) < uintptr_t(alt_stack + ALT_STACK_SIZE) &&

libc/test/src/stdio/fileop_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ TEST_F(LlvmLibcFILETest, SimpleFileOperations) {
101101

102102
// This is not a readable file.
103103
ASSERT_THAT(LIBC_NAMESPACE::fread(data, 1, 1, file),
104-
returns(EQ(0)).with_errno(NE(0)));
104+
returns(EQ(static_cast<size_t>(0))).with_errno(NE(0)));
105105

106106
ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
107107

@@ -175,7 +175,7 @@ TEST_F(LlvmLibcFILETest, FOpenFWriteSizeGreaterThanOne) {
175175
// Trying to read more should fetch nothing.
176176
ASSERT_THAT(
177177
LIBC_NAMESPACE::fread(read_data, sizeof(MyStruct), WRITE_NMEMB, file),
178-
returns(EQ(0)).with_errno(EQ(0)));
178+
returns(EQ(static_cast<size_t>(0))).with_errno(EQ(0)));
179179
EXPECT_NE(LIBC_NAMESPACE::feof(file), 0);
180180
EXPECT_EQ(LIBC_NAMESPACE::ferror(file), 0);
181181
ASSERT_EQ(LIBC_NAMESPACE::fclose(file), 0);

libc/test/src/stdio/fopen_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
#include "test/UnitTest/Test.h"
1616

1717
TEST(LlvmLibcFOpenTest, PrintToFile) {
18-
int result;
1918

2019
FILE *file =
2120
LIBC_NAMESPACE::fopen(APPEND_LIBC_TEST("testdata/test.txt"), "w");
2221
ASSERT_FALSE(file == nullptr);
2322

2423
static constexpr char STRING[] = "A simple string written to a file\n";
25-
result = LIBC_NAMESPACE::fwrite(STRING, 1, sizeof(STRING) - 1, file);
26-
EXPECT_GE(result, 0);
24+
size_t result = LIBC_NAMESPACE::fwrite(STRING, 1, sizeof(STRING) - 1, file);
25+
EXPECT_GE(result, static_cast<size_t>(0));
2726

2827
ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
2928

0 commit comments

Comments
 (0)