Skip to content

Commit b10085d

Browse files
committed
[contrib][linux-kernel] Add standard warnings and -Werror to CI
Test the kernel build with the standard warnings enabled so that we don't miss issues like fixed in PR #2802. Stacked on top of PR #2802 so CI passes, so it includes the fix. But, I won't merge until it is merged, so @solbjorn gets the credit for the fix.
1 parent 32a8443 commit b10085d

File tree

6 files changed

+57
-39
lines changed

6 files changed

+57
-39
lines changed

contrib/linux-kernel/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ libzstd:
3939
-DSTATIC_BMI2=0 \
4040
-DZSTD_ADDRESS_SANITIZER=0 \
4141
-DZSTD_MEMORY_SANITIZER=0 \
42+
-DZSTD_DATAFLOW_SANITIZER=0 \
4243
-DZSTD_COMPRESS_HEAPMODE=1 \
4344
-UZSTD_NO_INLINE \
4445
-UNO_PREFETCH \
@@ -88,9 +89,16 @@ import-upstream:
8889
rm $(LINUX)/lib/zstd/common/xxhash.*
8990
rm $(LINUX)/lib/zstd/compress/zstdmt_*
9091

92+
DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
93+
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
94+
-Wstrict-prototypes -Wundef -Wpointer-arith \
95+
-Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
96+
-Wredundant-decls -Wmissing-prototypes -Wc++-compat \
97+
-Wimplicit-fallthrough
98+
9199
.PHONY: test
92100
test: libzstd
93-
$(MAKE) -C test run-test CFLAGS="-O3 $(CFLAGS)" -j
101+
$(MAKE) -C test run-test CFLAGS="-O3 $(CFLAGS) $(DEBUGFLAGS) -Werror" -j
94102

95103
.PHONY: clean
96104
clean:

contrib/linux-kernel/test/include/asm/unaligned.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static unsigned _isLittleEndian(void)
2020
{
2121
const union { uint32_t u; uint8_t c[4]; } one = { 1 };
2222
assert(_IS_LITTLE_ENDIAN == one.c[0]);
23+
(void)one;
2324
return _IS_LITTLE_ENDIAN;
2425
}
2526

contrib/linux-kernel/test/include/linux/xxhash.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ XXH_API uint64_t xxh64(const void *input, size_t length, uint64_t seed);
124124
static inline unsigned long xxhash(const void *input, size_t length,
125125
uint64_t seed)
126126
{
127-
#if BITS_PER_LONG == 64
128-
return xxh64(input, length, seed);
129-
#else
130-
return xxh32(input, length, seed);
131-
#endif
127+
if (sizeof(size_t) == 8)
128+
return xxh64(input, length, seed);
129+
else
130+
return xxh32(input, length, seed);
132131
}
133132

134133
/*-****************************

contrib/linux-kernel/test/static_test.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ static const char kEmptyZstdFrame[] = {
2828
0x28, 0xb5, 0x2f, 0xfd, 0x24, 0x00, 0x01, 0x00, 0x00, 0x99, 0xe9, 0xd8, 0x51
2929
};
3030

31-
static void test_decompress_unzstd() {
31+
static void test_decompress_unzstd(void) {
3232
fprintf(stderr, "Testing decompress unzstd... ");
3333
{
3434
size_t const wkspSize = zstd_dctx_workspace_bound();
3535
void* wksp = malloc(wkspSize);
36-
CONTROL(wksp != NULL);
3736
ZSTD_DCtx* dctx = zstd_init_dctx(wksp, wkspSize);
37+
CONTROL(wksp != NULL);
3838
CONTROL(dctx != NULL);
39-
size_t const dSize = zstd_decompress_dctx(dctx, NULL, 0, kEmptyZstdFrame, sizeof(kEmptyZstdFrame));
40-
CONTROL(!zstd_is_error(dSize));
41-
CONTROL(dSize == 0);
39+
{
40+
size_t const dSize = zstd_decompress_dctx(dctx, NULL, 0, kEmptyZstdFrame, sizeof(kEmptyZstdFrame));
41+
CONTROL(!zstd_is_error(dSize));
42+
CONTROL(dSize == 0);
43+
}
4244
free(wksp);
4345
}
4446
fprintf(stderr, "Ok\n");

contrib/linux-kernel/test/test.c

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ typedef struct {
3030
size_t compSize;
3131
} test_data_t;
3232

33-
test_data_t create_test_data(void) {
33+
static test_data_t create_test_data(void) {
3434
test_data_t data;
3535
data.dataSize = 128 * 1024;
36-
data.data = malloc(data.dataSize);
36+
data.data = (char*)malloc(data.dataSize);
3737
CONTROL(data.data != NULL);
38-
data.data2 = malloc(data.dataSize);
38+
data.data2 = (char*)malloc(data.dataSize);
3939
CONTROL(data.data2 != NULL);
4040
data.compSize = zstd_compress_bound(data.dataSize);
41-
data.comp = malloc(data.compSize);
41+
data.comp = (char*)malloc(data.compSize);
4242
CONTROL(data.comp != NULL);
4343
memset(data.data, 0, data.dataSize);
4444
return data;
@@ -54,26 +54,27 @@ static void free_test_data(test_data_t const *data) {
5454
#define MAX(a, b) ((a) > (b) ? (a) : (b))
5555

5656
static void test_btrfs(test_data_t const *data) {
57-
fprintf(stderr, "testing btrfs use cases... ");
5857
size_t const size = MIN(data->dataSize, 128 * 1024);
58+
fprintf(stderr, "testing btrfs use cases... ");
5959
for (int level = -1; level < 16; ++level) {
6060
zstd_parameters params = zstd_get_params(level, size);
61-
CONTROL(params.cParams.windowLog <= 17);
6261
size_t const workspaceSize =
6362
MAX(zstd_cstream_workspace_bound(&params.cParams),
6463
zstd_dstream_workspace_bound(size));
6564
void *workspace = malloc(workspaceSize);
66-
CONTROL(workspace != NULL);
6765

6866
char const *ip = data->data;
6967
char const *iend = ip + size;
7068
char *op = data->comp;
7169
char *oend = op + data->compSize;
70+
71+
CONTROL(params.cParams.windowLog <= 17);
72+
CONTROL(workspace != NULL);
7273
{
7374
zstd_cstream *cctx = zstd_init_cstream(&params, size, workspace, workspaceSize);
74-
CONTROL(cctx != NULL);
7575
zstd_out_buffer out = {NULL, 0, 0};
7676
zstd_in_buffer in = {NULL, 0, 0};
77+
CONTROL(cctx != NULL);
7778
for (;;) {
7879
if (in.pos == in.size) {
7980
in.src = ip;
@@ -108,9 +109,9 @@ static void test_btrfs(test_data_t const *data) {
108109
oend = op + size;
109110
{
110111
zstd_dstream *dctx = zstd_init_dstream(1ULL << params.cParams.windowLog, workspace, workspaceSize);
111-
CONTROL(dctx != NULL);
112112
zstd_out_buffer out = {NULL, 0, 0};
113113
zstd_in_buffer in = {NULL, 0, 0};
114+
CONTROL(dctx != NULL);
114115
for (;;) {
115116
if (in.pos == in.size) {
116117
in.src = ip;
@@ -125,30 +126,31 @@ static void test_btrfs(test_data_t const *data) {
125126
out.pos = 0;
126127
op += out.size;
127128
}
128-
129-
size_t const ret = zstd_decompress_stream(dctx, &out, &in);
130-
CONTROL(!zstd_is_error(ret));
131-
if (ret == 0) {
132-
break;
129+
{
130+
size_t const ret = zstd_decompress_stream(dctx, &out, &in);
131+
CONTROL(!zstd_is_error(ret));
132+
if (ret == 0) {
133+
break;
134+
}
133135
}
134136
}
135137
}
136-
CONTROL(op - data->data2 == data->dataSize);
138+
CONTROL((size_t)(op - data->data2) == data->dataSize);
137139
CONTROL(!memcmp(data->data, data->data2, data->dataSize));
138140
free(workspace);
139141
}
140142
fprintf(stderr, "Ok\n");
141143
}
142144

143145
static void test_decompress_unzstd(test_data_t const *data) {
144-
fprintf(stderr, "Testing decompress unzstd... ");
145146
size_t cSize;
147+
fprintf(stderr, "Testing decompress unzstd... ");
146148
{
147149
zstd_parameters params = zstd_get_params(19, 0);
148150
size_t const wkspSize = zstd_cctx_workspace_bound(&params.cParams);
149151
void* wksp = malloc(wkspSize);
150-
CONTROL(wksp != NULL);
151152
zstd_cctx* cctx = zstd_init_cctx(wksp, wkspSize);
153+
CONTROL(wksp != NULL);
152154
CONTROL(cctx != NULL);
153155
cSize = zstd_compress_cctx(cctx, data->comp, data->compSize, data->data, data->dataSize, &params);
154156
CONTROL(!zstd_is_error(cSize));
@@ -157,19 +159,21 @@ static void test_decompress_unzstd(test_data_t const *data) {
157159
{
158160
size_t const wkspSize = zstd_dctx_workspace_bound();
159161
void* wksp = malloc(wkspSize);
160-
CONTROL(wksp != NULL);
161162
zstd_dctx* dctx = zstd_init_dctx(wksp, wkspSize);
163+
CONTROL(wksp != NULL);
162164
CONTROL(dctx != NULL);
163-
size_t const dSize = zstd_decompress_dctx(dctx, data->data2, data->dataSize, data->comp, cSize);
164-
CONTROL(!zstd_is_error(dSize));
165-
CONTROL(dSize == data->dataSize);
165+
{
166+
size_t const dSize = zstd_decompress_dctx(dctx, data->data2, data->dataSize, data->comp, cSize);
167+
CONTROL(!zstd_is_error(dSize));
168+
CONTROL(dSize == data->dataSize);
169+
}
166170
CONTROL(!memcmp(data->data, data->data2, data->dataSize));
167171
free(wksp);
168172
}
169173
fprintf(stderr, "Ok\n");
170174
}
171175

172-
static void test_f2fs() {
176+
static void test_f2fs(void) {
173177
fprintf(stderr, "testing f2fs uses... ");
174178
CONTROL(zstd_min_clevel() < 0);
175179
CONTROL(zstd_max_clevel() == 22);
@@ -182,22 +186,24 @@ static void __attribute__((noinline)) use(void *x) {
182186
asm volatile("" : "+r"(x));
183187
}
184188

185-
static void __attribute__((noinline)) set_stack() {
189+
static void __attribute__((noinline)) set_stack(void) {
186190

187191
char stack[8192];
188192
g_stack = stack;
189193
memset(g_stack, 0x33, 8192);
190194
use(g_stack);
191195
}
192196

193-
static void __attribute__((noinline)) check_stack() {
197+
static void __attribute__((noinline)) check_stack(void) {
194198
size_t cleanStack = 0;
195199
while (cleanStack < 8192 && g_stack[cleanStack] == 0x33) {
196200
++cleanStack;
197201
}
198-
size_t const stackSize = 8192 - cleanStack;
199-
fprintf(stderr, "Maximum stack size: %zu\n", stackSize);
200-
CONTROL(stackSize <= 2048 + 512);
202+
{
203+
size_t const stackSize = 8192 - cleanStack;
204+
fprintf(stderr, "Maximum stack size: %zu\n", stackSize);
205+
CONTROL(stackSize <= 2048 + 512);
206+
}
201207
}
202208

203209
static void test_stack_usage(test_data_t const *data) {

lib/decompress/huf_decompress.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
* Disable when MSAN is enabled.
4848
*/
4949
#if defined(__linux__) || defined(__linux) || defined(__APPLE__)
50-
# if ZSTD_MEMORY_SANITIZER || ZSTD_DATAFLOW_SANITIZER
50+
# if ZSTD_MEMORY_SANITIZER
51+
# define HUF_ASM_SUPPORTED 0
52+
# elif ZSTD_DATAFLOW_SANITIZER
5153
# define HUF_ASM_SUPPORTED 0
5254
# else
5355
# define HUF_ASM_SUPPORTED 1

0 commit comments

Comments
 (0)