Skip to content

Commit c2989f3

Browse files
authored
Enable more build warnings for libc-bottom-half (WebAssembly#755)
While wasi-libc is compiled with `-Wall -Wextra` it ended up disabling a lot of warnings as well to handle third-party code. This commit reorganizes things by continuing to compile everything with `-Wall -Wextra` but disabling lints is done exclusively for third-party code rather than for all code in wasi-libc. In practice this means that everything in `libc-bottom-half`, code written exclusively for this repository, now has more lints firing. This additionally applies to `test/src/*.c`. Much of this commit is handling these lints then and adjusting a few patterns in places where necessary. This commit additionally disables compiling with `-Werror` by default. CI still enables this by default, but it means that new lints/warnings won't be breaking for anyone else other than this repository's own CI which should have pinned versions of Clang being used in various places.
1 parent 426da18 commit c2989f3

75 files changed

Lines changed: 257 additions & 147 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
os: ubuntu-22.04
4848
clang_version: 11
4949
upload: linux-x86_64-clang-11
50-
args: -DSETJMP=OFF -DBUILD_SHARED=OFF
50+
args: -DSETJMP=OFF -DBUILD_SHARED=OFF -DENABLE_WERROR=OFF
5151
- name: Build with LLVM 18
5252
os: ubuntu-24.04
5353
clang_version: 18
@@ -177,7 +177,7 @@ jobs:
177177
178178
- name: Configure testing
179179
if: matrix.test
180-
run: cmake -S . -B build -DBUILD_TESTS=ON -DENGINE=${{ env.ENGINE }}
180+
run: cmake -S . -B build -DENABLE_WERROR=ON -DBUILD_TESTS=ON -DENGINE=${{ env.ENGINE }}
181181

182182
- name: Build
183183
run: ninja -C build -v

CMakeLists.txt

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ option(SIMD "Whether or not to build simd-enabled intrinsics into wasi-libc" OFF
5050
option(BUILD_SHARED "Whether or not to build shared libraries" ON)
5151
option(CHECK_SYMBOLS "Whether or not to check the exported symbols of libc.a" OFF)
5252
set(WASI_SDK_VERSION "" CACHE STRING "Version information for wasi-sdk to embed in headers")
53+
option(ENABLE_WERROR "Whether to compile with `-Werror`" OFF)
5354

5455
if(TARGET_TRIPLE MATCHES "-threads$")
5556
set(WASI p1)
@@ -195,25 +196,19 @@ add_compile_options(
195196
# TODO: Add -fno-signaling-nans when the compiler supports it.
196197
-fno-trapping-math
197198

198-
# Add all warnings, but disable a few which occur in third-party code.
199-
-Wall -Wextra -Werror
200-
-Wno-null-pointer-arithmetic
201-
-Wno-unused-parameter
202-
-Wno-sign-compare
203-
-Wno-unused-variable
204-
-Wno-unused-function
205-
-Wno-ignored-attributes
206-
-Wno-missing-braces
207-
-Wno-ignored-pragmas
208-
-Wno-unused-but-set-variable
209-
-Wno-unknown-warning-option
210-
-Wno-unterminated-string-initialization
199+
# Add all warnings. Note that third-party code is compiled with extra flags
200+
# to disable warnings that crop up.
201+
-Wall -Wextra
211202

212203
# Compiling assembly flags lots of arguments as unused but that's not too
213204
# interesting so just ignore that.
214205
$<$<COMPILE_LANGUAGE:ASM>:-Wno-unused-command-line-argument>
215206
)
216207

208+
if (ENABLE_WERROR)
209+
add_compile_options(-Werror)
210+
endif()
211+
217212
# =============================================================================
218213
# Helper functions for adding libraries.
219214

dlmalloc/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Disable some warnings in this third-party code.
2+
add_compile_options(-Wno-null-pointer-arithmetic -Wno-unused-but-set-variable)
3+
14
add_object_library(dlmalloc src/dlmalloc.c)
25
foreach(obj dlmalloc-shared dlmalloc-static)
36
target_include_directories(${obj} PRIVATE include)

emmalloc/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Disable some warnings in this third-party code.
2+
add_compile_options(-Wno-unused-function)
13
add_object_library(emmalloc emmalloc.c)
24

35
# emmalloc uses a lot of pointer type-punning, which is UB under strict

fts/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Disable some warnings in this third-party code.
2+
add_compile_options(-Wno-unused-parameter -Wno-unused-variable)
3+
14
add_internal_object_library(fts musl-fts/fts.c)
25
foreach(obj fts-shared fts-static)
36
target_include_directories(${obj} PRIVATE . musl-fts)

libc-bottom-half/cloudlibc/src/common/errors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <errno.h>
55
#include <stdlib.h>
66

7-
static void translate_error(filesystem_error_code_t error) {
7+
static inline void translate_error(filesystem_error_code_t error) {
88
switch (error) {
99
case FILESYSTEM_ERROR_CODE_ACCESS:
1010
errno = EACCES;

libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ DIR *fdopendir(int fd) {
7777
dirp->dirent_size = 1;
7878
return dirp;
7979
#elif defined(__wasip3__)
80+
(void) fd;
8081
// TODO(wasip3)
8182
errno = ENOTSUP;
8283
free(dirp);

libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static_assert(DT_UNKNOWN == __WASI_FILETYPE_UNKNOWN, "Value mismatch");
3232
#endif
3333

3434
// Grows a buffer to be large enough to hold a certain amount of data.
35+
#ifndef __wasip3__
3536
static struct dirent* grow(struct dirent **buffer, size_t *buffer_size, size_t target_size) {
3637
if (*buffer_size < target_size) {
3738
size_t new_size = *buffer_size;
@@ -47,6 +48,7 @@ static struct dirent* grow(struct dirent **buffer, size_t *buffer_size, size_t t
4748
}
4849
return *buffer;
4950
}
51+
#endif
5052

5153
#if defined(__wasip1__)
5254
struct dirent *readdir(DIR *dirp) {

libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
#include <stdlib.h>
99
#include <string.h>
1010

11-
static int sel_true(const struct dirent *de) {
12-
return 1;
13-
}
14-
1511
int __wasilibc_nocwd_scandirat(int dirfd, const char *dir, struct dirent ***res,
1612
int (*sel)(const struct dirent *),
1713
int (*cmp)(const struct dirent **, const struct dirent **)) {

libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ int __wasilibc_nocwd_openat_nomode(int fd, const char *path, int oflag) {
162162
// Update the descriptor table with the new handle
163163
return __wasilibc_add_file(new_handle, oflag);
164164
#elif defined(__wasip3__)
165+
(void) fd;
166+
(void) path;
167+
(void) oflag;
165168
// TODO(wasip3)
166169
errno = ENOTSUP;
167170
return -1;

0 commit comments

Comments
 (0)