Skip to content

Commit e617dc8

Browse files
[libc] Add -Wextra for libc tests (#133643)
* Relates to: llvm/llvm-project#119281
1 parent ab323eb commit e617dc8

27 files changed

+108
-58
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function(_get_common_test_compile_options output_var c_test flags)
4040
endif()
4141

4242
# list(APPEND compile_options "-Wall")
43-
# list(APPEND compile_options "-Wextra")
43+
list(APPEND compile_options "-Wextra")
4444
# -DLIBC_WNO_ERROR=ON if you can't build cleanly with -Werror.
4545
if(NOT LIBC_WNO_ERROR)
4646
# list(APPEND compile_options "-Werror")

libc/test/UnitTest/FPExceptMatcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace testing {
3131
static thread_local sigjmp_buf jumpBuffer;
3232
static thread_local bool caughtExcept;
3333

34-
static void sigfpeHandler(int sig) {
34+
static void sigfpeHandler([[maybe_unused]] int sig) {
3535
caughtExcept = true;
3636
siglongjmp(jumpBuffer, -1);
3737
}

libc/test/UnitTest/FPExceptMatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class FPExceptMatcher : public Matcher<bool> {
4343
// Takes ownership of func.
4444
explicit FPExceptMatcher(FunctionCaller *func);
4545

46-
bool match(bool unused) { return exceptionRaised; }
46+
bool match([[maybe_unused]] bool unused) { return exceptionRaised; }
4747

4848
void explainError() override {
4949
tlog << "A floating point exception should have been raised but it "

libc/test/UnitTest/HermeticTestUtils.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ int atexit(void (*func)(void));
2929
// add_libc_hermetic_test properly. Such that they won't get correct linkage
3030
// against the object containing this function. We create a dummy function that
3131
// always returns 0 to indicate a failure.
32-
[[gnu::weak]] unsigned long getauxval(unsigned long id) { return 0; }
32+
[[gnu::weak]] unsigned long getauxval([[maybe_unused]] unsigned long id) {
33+
return 0;
34+
}
3335

3436
} // namespace LIBC_NAMESPACE_DECL
3537

@@ -124,7 +126,7 @@ unsigned long __getauxval(unsigned long id) {
124126

125127
} // extern "C"
126128

127-
void *operator new(size_t size, void *ptr) { return ptr; }
129+
void *operator new([[maybe_unused]] size_t size, void *ptr) { return ptr; }
128130

129131
void *operator new(size_t size) { return malloc(size); }
130132

@@ -136,7 +138,9 @@ void operator delete(void *) {
136138
__builtin_trap();
137139
}
138140

139-
void operator delete(void *ptr, size_t size) { __builtin_trap(); }
141+
void operator delete([[maybe_unused]] void *ptr, [[maybe_unused]] size_t size) {
142+
__builtin_trap();
143+
}
140144

141145
// Defining members in the std namespace is not preferred. But, we do it here
142146
// so that we can use it to define the operator new which takes std::align_val_t
@@ -145,8 +149,11 @@ namespace std {
145149
enum class align_val_t : size_t {};
146150
} // namespace std
147151

148-
void operator delete(void *mem, std::align_val_t) noexcept { __builtin_trap(); }
152+
void operator delete([[maybe_unused]] void *mem, std::align_val_t) noexcept {
153+
__builtin_trap();
154+
}
149155

150-
void operator delete(void *mem, unsigned int, std::align_val_t) noexcept {
156+
void operator delete([[maybe_unused]] void *mem, unsigned int,
157+
std::align_val_t) noexcept {
151158
__builtin_trap();
152159
}

libc/test/UnitTest/LibcDeathTestExecutors.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace LIBC_NAMESPACE_DECL {
2222
namespace testing {
2323

2424
bool Test::testProcessKilled(testutils::FunctionCaller *Func, int Signal,
25-
const char *LHSStr, const char *RHSStr,
25+
const char *LHSStr,
26+
[[maybe_unused]] const char *RHSStr,
2627
internal::Location Loc) {
2728
testutils::ProcessStatus Result =
2829
testutils::invoke_in_subprocess(Func, TIMEOUT_MS);

libc/test/UnitTest/LibcTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct Message {
8181
// A trivial object to catch the Message, this enables custom logging and
8282
// returning from the test function, see LIBC_TEST_SCAFFOLDING_ below.
8383
struct Failure {
84-
void operator=(Message msg) {}
84+
void operator=([[maybe_unused]] Message msg) {}
8585
};
8686

8787
struct RunContext {

libc/test/include/stdbit_stub.h

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@
1717
#include <stdbool.h> // bool in C
1818

1919
#define STDBIT_STUB_FUNCTION(FUNC_NAME, LEADING_VAL) \
20-
unsigned FUNC_NAME##_uc(unsigned char x) { return LEADING_VAL##AU; } \
21-
unsigned FUNC_NAME##_us(unsigned short x) { return LEADING_VAL##BU; } \
22-
unsigned FUNC_NAME##_ui(unsigned int x) { return LEADING_VAL##CU; } \
23-
unsigned FUNC_NAME##_ul(unsigned long x) { return LEADING_VAL##DU; } \
24-
unsigned FUNC_NAME##_ull(unsigned long long x) { return LEADING_VAL##EU; }
20+
unsigned FUNC_NAME##_uc([[maybe_unused]] unsigned char x) { \
21+
return LEADING_VAL##AU; \
22+
} \
23+
unsigned FUNC_NAME##_us([[maybe_unused]] unsigned short x) { \
24+
return LEADING_VAL##BU; \
25+
} \
26+
unsigned FUNC_NAME##_ui([[maybe_unused]] unsigned int x) { \
27+
return LEADING_VAL##CU; \
28+
} \
29+
unsigned FUNC_NAME##_ul([[maybe_unused]] unsigned long x) { \
30+
return LEADING_VAL##DU; \
31+
} \
32+
unsigned FUNC_NAME##_ull([[maybe_unused]] unsigned long long x) { \
33+
return LEADING_VAL##EU; \
34+
}
2535

2636
__BEGIN_C_DECLS
2737

@@ -36,24 +46,42 @@ STDBIT_STUB_FUNCTION(stdc_first_trailing_one, 0x1)
3646
STDBIT_STUB_FUNCTION(stdc_count_zeros, 0x2)
3747
STDBIT_STUB_FUNCTION(stdc_count_ones, 0x3)
3848

39-
bool stdc_has_single_bit_uc(unsigned char x) { return false; }
40-
bool stdc_has_single_bit_us(unsigned short x) { return false; }
41-
bool stdc_has_single_bit_ui(unsigned x) { return false; }
42-
bool stdc_has_single_bit_ul(unsigned long x) { return false; }
43-
bool stdc_has_single_bit_ull(unsigned long long x) { return false; }
49+
bool stdc_has_single_bit_uc([[maybe_unused]] unsigned char x) { return false; }
50+
bool stdc_has_single_bit_us([[maybe_unused]] unsigned short x) { return false; }
51+
bool stdc_has_single_bit_ui([[maybe_unused]] unsigned x) { return false; }
52+
bool stdc_has_single_bit_ul([[maybe_unused]] unsigned long x) { return false; }
53+
bool stdc_has_single_bit_ull([[maybe_unused]] unsigned long long x) {
54+
return false;
55+
}
4456

4557
STDBIT_STUB_FUNCTION(stdc_bit_width, 0x4)
4658

47-
unsigned char stdc_bit_floor_uc(unsigned char x) { return 0x5AU; }
48-
unsigned short stdc_bit_floor_us(unsigned short x) { return 0x5BU; }
49-
unsigned stdc_bit_floor_ui(unsigned x) { return 0x5CU; }
50-
unsigned long stdc_bit_floor_ul(unsigned long x) { return 0x5DUL; }
51-
unsigned long long stdc_bit_floor_ull(unsigned long long x) { return 0x5EULL; }
52-
53-
unsigned char stdc_bit_ceil_uc(unsigned char x) { return 0x6AU; }
54-
unsigned short stdc_bit_ceil_us(unsigned short x) { return 0x6BU; }
55-
unsigned stdc_bit_ceil_ui(unsigned x) { return 0x6CU; }
56-
unsigned long stdc_bit_ceil_ul(unsigned long x) { return 0x6DUL; }
57-
unsigned long long stdc_bit_ceil_ull(unsigned long long x) { return 0x6EULL; }
59+
unsigned char stdc_bit_floor_uc([[maybe_unused]] unsigned char x) {
60+
return 0x5AU;
61+
}
62+
unsigned short stdc_bit_floor_us([[maybe_unused]] unsigned short x) {
63+
return 0x5BU;
64+
}
65+
unsigned stdc_bit_floor_ui([[maybe_unused]] unsigned x) { return 0x5CU; }
66+
unsigned long stdc_bit_floor_ul([[maybe_unused]] unsigned long x) {
67+
return 0x5DUL;
68+
}
69+
unsigned long long stdc_bit_floor_ull([[maybe_unused]] unsigned long long x) {
70+
return 0x5EULL;
71+
}
72+
73+
unsigned char stdc_bit_ceil_uc([[maybe_unused]] unsigned char x) {
74+
return 0x6AU;
75+
}
76+
unsigned short stdc_bit_ceil_us([[maybe_unused]] unsigned short x) {
77+
return 0x6BU;
78+
}
79+
unsigned stdc_bit_ceil_ui([[maybe_unused]] unsigned x) { return 0x6CU; }
80+
unsigned long stdc_bit_ceil_ul([[maybe_unused]] unsigned long x) {
81+
return 0x6DUL;
82+
}
83+
unsigned long long stdc_bit_ceil_ull([[maybe_unused]] unsigned long long x) {
84+
return 0x6EULL;
85+
}
5886

5987
__END_C_DECLS

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ constexpr int MAX = 10000;
2323
pthread_mutex_t mutex;
2424
static int shared_int = START;
2525

26-
void *counter(void *arg) {
26+
void *counter([[maybe_unused]] void *arg) {
2727
int last_count = START;
2828
while (true) {
2929
LIBC_NAMESPACE::pthread_mutex_lock(&mutex);
@@ -72,7 +72,7 @@ void relay_counter() {
7272
pthread_mutex_t start_lock, step_lock;
7373
bool started, step;
7474

75-
void *stepper(void *arg) {
75+
void *stepper([[maybe_unused]] void *arg) {
7676
LIBC_NAMESPACE::pthread_mutex_lock(&start_lock);
7777
started = true;
7878
LIBC_NAMESPACE::pthread_mutex_unlock(&start_lock);

libc/test/integration/src/spawn/posix_spawn_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ void spawn_and_wait_for_normal_exit(char **envp) {
4545
ASSERT_EQ(exit_status, 0);
4646
}
4747

48-
TEST_MAIN(int argc, char **argv, char **envp) {
48+
TEST_MAIN([[maybe_unused]] int argc, [[maybe_unused]] char **argv,
49+
char **envp) {
4950
spawn_and_wait_for_normal_exit(envp);
5051
return 0;
5152
}

libc/test/integration/src/spawn/posix_spawn_test_binary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <string.h>
33
#include <unistd.h>
44

5-
int main(int argc, char **argv) {
5+
int main(int argc, [[maybe_unused]] char **argv) {
66
if (argc != 1)
77
return 5;
88
constexpr size_t bufsize = sizeof(TEXT);

0 commit comments

Comments
 (0)