From d78fcae24d7b33f725dba3eac07f0c3bfe59beda Mon Sep 17 00:00:00 2001 From: Julien Fischer Date: Sat, 5 Mar 2022 22:39:10 +1100 Subject: [PATCH] Avoid spurious warnings from GCC. As mentioned recently on the developers list, GCC versions 9 10 and 11 are emitting suprious warnings with -Warray-bounds for the specialised code they introduce for strcmp etc. Disable that warning for those versions of GCC. In addition to this issue, according to the GCC bug database is is generating a lot of false positives anyway. configure.ac: scripts/mgnuc.in: As above. --- configure.ac | 8 ++++++++ scripts/mgnuc.in | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/configure.ac b/configure.ac index fab0809cb..384349fa8 100644 --- a/configure.ac +++ b/configure.ac @@ -4368,6 +4368,14 @@ case "$mercury_cv_cc_type" in # and why, see scripts/mgnuc.in. CFLAGS_FOR_WARNINGS="-Wall -Wwrite-strings -Wshadow -Wmissing-prototypes -Wno-unused -Wno-uninitialized -Wstrict-prototypes" + # See scripts/mgnuc.in for an explanation of why we set + # -Wno-array-bounds here. + case "$C_COMPILER_TYPE" in + gcc_9_*|gcc_10_*|gcc_11_*) + CFLAGS_FOR_WARNINGS="$CFLAGS_FOR_WARNINGS -Wno-array-bounds" + ;; + esac + # Enabling -fomit-frame-pointer causes setjmp/longjmp to misbehave # with MinGW on Windows XP. case "$host" in diff --git a/scripts/mgnuc.in b/scripts/mgnuc.in index fb004e275..f4eece538 100755 --- a/scripts/mgnuc.in +++ b/scripts/mgnuc.in @@ -570,6 +570,17 @@ case "${FULLARCH}" in ;; esac +# gcc versions 9, 10 and 11 replace calls to strcmp and related functions with +# specialised code when some of the arguments are string constants. +# The above versions of gcc emit spurious warnings about the code they +# introduce when -Warray-bounds is enabled. +# +case "${C_COMPILER_TYPE}" in + gcc_9_*|gcc_10_*|gcc_11_*) + CHECK_OPTS="${CHECK_OPTS} -Wno-array-bounds" + ;; +esac + case ${COMPILER} in gcc) case "${FULLARCH}" in i*86*)