build: set CFLAGS "-Wno-error=maybe-uninitialized" with LTO build

With LTO builds we get "-Wmaybe-uninitialized" warnings, which break
the build.

These seem false positives to me, due to aggressive inlining. But also
suppressing them with a pragma does not work. So, make them non-fatal
altogether. That is unfortunate, because this warning would be useful
to catch bugs.

Interestingly, when building --with-more-asserts, then the build passes
without warning. Probably because then the inlining doesn't happen.

    libtool: link: gcc -Wall -Werror -Wno-stringop-overflow -Wextra -Wdeclaration-after-statement -Wfloat-equal -Wformat-nonliteral -Wformat-security -Wimplicit-function-declaration -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wpointer-arith -Wshadow -Wshift-negative-value -Wstrict-prototypes -Wundef -Wvla -Wno-duplicate-decl-specifier -Wno-format-truncation -Wno-format-y2k -Wno-missing-field-initializers -Wno-pragmas -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-parameter -Wno-array-bounds -Wunused-value -Wcast-function-type -Wimplicit-fallthrough -fno-strict-aliasing -fdata-sections -ffunction-sections -Wl,--gc-sections -flto -flto-partition=none -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Wl,-z -Wl,relro -Wl,--as-needed -Wl,-z -Wl,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -o src/platform/tests/test-platform-general src/platform/tests/test_platform_general-test-platform-general.o  src/.libs/libNetworkManagerTest.a -luuid -lgnutls -lsystemd -lndp -lselinux -L/lib64 -laudit -lpsl -lcurl -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -ludev -ldl -pthread
    src/platform/nm-linux-platform.c: In function 'ip_route_add':
    src/platform/nm-platform.c:4761:24: error: 'MEM[(struct NMPlatformIPRoute *)&obj + 24B].rt_source' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     4761 |     route->rt_source = nmp_utils_ip_config_source_round_trip_rtprot(route->rt_source);
          |                        ^
    src/platform/nm-platform.h:2139:25: error: 'BIT_FIELD_REF <MEM[(const struct NMPlatformIPRoute *)&obj + 24B], 8, 72>' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     2139 |     return r->table_any ? 254u /* RT_TABLE_MAIN */
          |                         ^
    lto1: all warnings being treated as errors
    lto-wrapper: fatal error: gcc returned 1 exit status
This commit is contained in:
Thomas Haller 2021-01-08 11:18:35 +01:00
parent f8026717e4
commit 1d63271a8d
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -62,8 +62,12 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
if test "x$enable_lto" = xyes; then
dnl With LTO and optimizations enabled, gcc 10.2.1-1.fc32 is really
dnl adamant to warn about correct uses of strncpy. Disable that warning.
_CFLAGS_MORE_WARNINGS_DISABLE_LTO="-Wno-stringop-overflow"
dnl adamant to warn about correct uses of strncpy. Disable "-Wstringop-overflow".
dnl
dnl Also, due to aggressive inlining, we get maybe-uninitialized false positives
dnl that are really hard to suppress. That is unfortunate, because generally
dnl these warnings are useful. Can't help it. Make them non-fatal.
_CFLAGS_MORE_WARNINGS_DISABLE_LTO="-Wno-stringop-overflow -Wno-error=maybe-uninitialized"
else
_CFLAGS_MORE_WARNINGS_DISABLE_LTO=
fi
@ -102,7 +106,7 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
-Wno-unused-parameter \
; do
dnl GCC 4.4 does not warn when checking for -Wno-* flags (https://gcc.gnu.org/wiki/FAQ#wnowarning)
_NM_COMPILER_FLAG([-Wall $(printf '%s' "$option" | sed 's/^-Wno-/-W/')], [],
_NM_COMPILER_FLAG([-Wall $(printf '%s' "$option" | sed -e 's/^-W\(no-\|no-error=\)/-W/')], [],
[CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS $option"], [])
done
unset option