Skip to content

Commit 97d6249

Browse files
committed
Fix GCC and Clang errors on Ubuntu 22.10
Make the code compile on Ubuntu Kinetic. - Clang 15 doesn't support `-fno-ipa-sra` anymore. - Squelch false positives. Signed-off-by: szubersk <[email protected]>
1 parent ecbf027 commit 97d6249

File tree

9 files changed

+91
-4
lines changed

9 files changed

+91
-4
lines changed

cmd/zfs/zfs_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ usage(boolean_t requested)
548548
show_properties = B_TRUE;
549549

550550
if (show_properties) {
551-
(void) fprintf(fp,
551+
(void) fprintf(fp, "%s",
552552
gettext("\nThe following properties are supported:\n"));
553553

554554
(void) fprintf(fp, "\n\t%-14s %s %s %s\n\n",

cmd/zpool/zpool_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ usage(boolean_t requested)
548548
(strcmp(current_command->name, "get") == 0) ||
549549
(strcmp(current_command->name, "list") == 0))) {
550550

551-
(void) fprintf(fp,
551+
(void) fprintf(fp, "%s",
552552
gettext("\nthe following properties are supported:\n"));
553553

554554
(void) fprintf(fp, "\n\t%-19s %s %s\n\n",

config/Rules.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ AM_CPPFLAGS += -DSYSCONFDIR=\"$(sysconfdir)\"
3939
AM_CPPFLAGS += -DPKGDATADIR=\"$(pkgdatadir)\"
4040
AM_CPPFLAGS += $(DEBUG_CPPFLAGS)
4141
AM_CPPFLAGS += $(CODE_COVERAGE_CPPFLAGS)
42+
AM_CPPFLAGS += $(FORMAT_OVERFLOW_SUPPORTED)
4243
AM_CPPFLAGS += -DTEXT_DOMAIN=\"zfs-@ac_system_l@-user\"
4344

4445
AM_CPPFLAGS_NOCHECK = -D"strtok(...)=strtok(__VA_ARGS__) __attribute__((deprecated(\"Use strtok_r(3) instead!\")))"

config/always-compiler-options.m4

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,27 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_INFINITE_RECURSION], [
227227
AC_SUBST([INFINITE_RECURSION])
228228
])
229229

230+
dnl #
231+
dnl # Check if cc supports -Wformat-overflow option.
232+
dnl #
233+
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_FORMAT_OVERFLOW_SUPPORTED], [
234+
AC_MSG_CHECKING([whether $CC supports -Wformat-overflow])
235+
236+
saved_flags="$CFLAGS"
237+
CFLAGS="$CFLAGS -Werror -Wformat-overflow"
238+
239+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
240+
FORMAT_OVERFLOW_SUPPORTED=-DZFS_GCC_FORMAT_OVERFLOW_SUPPORTED
241+
AC_MSG_RESULT([yes])
242+
], [
243+
FORMAT_OVERFLOW_SUPPORTED=
244+
AC_MSG_RESULT([no])
245+
])
246+
247+
CFLAGS="$saved_flags"
248+
AC_SUBST([FORMAT_OVERFLOW_SUPPORTED])
249+
])
250+
230251
dnl #
231252
dnl # Check if cc supports -fno-omit-frame-pointer option.
232253
dnl #
@@ -268,3 +289,33 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA], [
268289
CFLAGS="$saved_flags"
269290
AC_SUBST([NO_IPA_SRA])
270291
])
292+
293+
dnl #
294+
dnl # Check if kernel cc supports -fno-ipa-sra option.
295+
dnl #
296+
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_NO_IPA_SRA], [
297+
AC_MSG_CHECKING([whether $KERNEL_CC supports -fno-ipa-sra])
298+
299+
saved_cc="$CC"
300+
saved_flags="$CFLAGS"
301+
CFLAGS="$CFLAGS -Werror -fno-ipa-sra"
302+
303+
AS_IF([ test -n "$KERNEL_CC" ], [
304+
CC="$KERNEL_CC"
305+
])
306+
AS_IF([ test -n "$KERNEL_LLVM" ], [
307+
CC="clang"
308+
])
309+
310+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
311+
KERNEL_NO_IPA_SRA=-fno-ipa-sra
312+
AC_MSG_RESULT([yes])
313+
], [
314+
KERNEL_NO_IPA_SRA=
315+
AC_MSG_RESULT([no])
316+
])
317+
318+
CC="$saved_cc"
319+
CFLAGS="$saved_flags"
320+
AC_SUBST([NO_IPA_SRA])
321+
])

config/zfs-build.m4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ AC_DEFUN([ZFS_AC_DEBUG], [
8181
AC_DEFUN([ZFS_AC_DEBUGINFO_ENABLE], [
8282
DEBUG_CFLAGS="$DEBUG_CFLAGS -g -fno-inline $NO_IPA_SRA"
8383
84-
KERNEL_DEBUG_CFLAGS="$KERNEL_DEBUG_CFLAGS -fno-inline $NO_IPA_SRA"
84+
KERNEL_DEBUG_CFLAGS="$KERNEL_DEBUG_CFLAGS -fno-inline $KERNEL_NO_IPA_SRA"
8585
KERNEL_MAKE="$KERNEL_MAKE CONFIG_DEBUG_INFO=y"
8686
8787
DEBUGINFO_ZFS="_with_debuginfo"
@@ -215,8 +215,10 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [
215215
ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN
216216
ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION
217217
ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_ZERO_LENGTH
218+
ZFS_AC_CONFIG_ALWAYS_CC_FORMAT_OVERFLOW_SUPPORTED
218219
ZFS_AC_CONFIG_ALWAYS_CC_NO_OMIT_FRAME_POINTER
219220
ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA
221+
ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_NO_IPA_SRA
220222
ZFS_AC_CONFIG_ALWAYS_CC_ASAN
221223
ZFS_AC_CONFIG_ALWAYS_CC_UBSAN
222224
ZFS_AC_CONFIG_ALWAYS_TOOLCHAIN_SIMD

lib/libnvpair/libnvpair.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ nvprint_##type_and_variant(nvlist_prtctl_t pctl, void *private, \
199199
return (1); \
200200
}
201201

202+
#if defined(__GNUC__) && !defined(__clang__) && \
203+
defined(ZFS_GCC_FORMAT_OVERFLOW_SUPPORTED)
204+
#pragma GCC diagnostic push
205+
#pragma GCC diagnostic ignored "-Wformat-overflow"
206+
#endif
202207
NVLIST_PRTFUNC(boolean, int, int, "%d")
203208
NVLIST_PRTFUNC(boolean_value, boolean_t, int, "%d")
204209
NVLIST_PRTFUNC(byte, uchar_t, uchar_t, "0x%2.2x")
@@ -213,6 +218,9 @@ NVLIST_PRTFUNC(uint64, uint64_t, u_longlong_t, "0x%llx")
213218
NVLIST_PRTFUNC(double, double, double, "0x%f")
214219
NVLIST_PRTFUNC(string, char *, char *, "%s")
215220
NVLIST_PRTFUNC(hrtime, hrtime_t, hrtime_t, "0x%llx")
221+
#if defined(__GNUC__) && !defined(__clang__)
222+
#pragma GCC diagnostic pop
223+
#endif
216224

217225
/*
218226
* Generate functions to print array-valued nvlist members.

lib/libzfs/libzfs_sendrecv.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,17 @@ send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap,
10071007
(void) fprintf(fout, dgettext(TEXT_DOMAIN,
10081008
"incremental\t%s\t%s"), fromsnap, tosnap);
10091009
} else {
1010+
#if defined(__GNUC__) && !defined(__clang__) && \
1011+
defined(ZFS_GCC_FORMAT_OVERFLOW_SUPPORTED)
1012+
#pragma GCC diagnostic push
1013+
#pragma GCC diagnostic ignored "-Wformat-overflow"
1014+
#endif
10101015
(void) fprintf(fout, dgettext(TEXT_DOMAIN,
10111016
"full\t%s"), tosnap);
1017+
#if defined(__GNUC__) && !defined(__clang__) && \
1018+
defined(ZFS_GCC_FORMAT_OVERFLOW_SUPPORTED)
1019+
#pragma GCC diagnostic pop
1020+
#endif
10121021
}
10131022
(void) fprintf(fout, "\t%llu", (longlong_t)size);
10141023
} else {
@@ -1028,8 +1037,17 @@ send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap,
10281037
if (size != 0) {
10291038
char buf[16];
10301039
zfs_nicebytes(size, buf, sizeof (buf));
1040+
#if defined(__GNUC__) && !defined(__clang__) && \
1041+
defined(ZFS_GCC_FORMAT_OVERFLOW_SUPPORTED)
1042+
#pragma GCC diagnostic push
1043+
#pragma GCC diagnostic ignored "-Wformat-overflow"
1044+
#endif
10311045
(void) fprintf(fout, dgettext(TEXT_DOMAIN,
10321046
" estimated size is %s"), buf);
1047+
#if defined(__GNUC__) && !defined(__clang__) && \
1048+
defined(ZFS_GCC_FORMAT_OVERFLOW_SUPPORTED)
1049+
#pragma GCC diagnostic pop
1050+
#endif
10331051
}
10341052
}
10351053
(void) fprintf(fout, "\n");

module/icp/algs/blake3/blake3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static size_t compress_parents_parallel(const blake3_ops_t *ops,
276276
const uint8_t *child_chaining_values, size_t num_chaining_values,
277277
const uint32_t key[8], uint8_t flags, uint8_t *out)
278278
{
279-
const uint8_t *parents_array[MAX_SIMD_DEGREE_OR_2];
279+
const uint8_t *parents_array[MAX_SIMD_DEGREE_OR_2] = {0};
280280
size_t parents_array_len = 0;
281281

282282
while (num_chaining_values - (2 * parents_array_len) >= 2) {

module/os/linux/zfs/zio_crypt.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,14 @@ zio_crypt_key_init(uint64_t crypt, zio_crypt_key_t *key)
229229
ASSERT(key != NULL);
230230
ASSERT3U(crypt, <, ZIO_CRYPT_FUNCTIONS);
231231

232+
#if defined(__GNUC__) && !defined(__clang__)
233+
#pragma GCC diagnostic push
234+
#pragma GCC diagnostic ignored "-Warray-bounds"
235+
#endif
232236
keydata_len = zio_crypt_table[crypt].ci_keylen;
237+
#if defined(__GNUC__) && !defined(__clang__)
238+
#pragma GCC diagnostic pop
239+
#endif
233240
memset(key, 0, sizeof (zio_crypt_key_t));
234241
rw_init(&key->zk_salt_lock, NULL, RW_DEFAULT, NULL);
235242

0 commit comments

Comments
 (0)