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*)