[m-rev.] diff: avoid spurious warnings from GCC

Julien Fischer jfischer at opturion.com
Sat Mar 5 22:28:37 AEDT 2022


Note: GCC 8 and before do not emit the spurious warnings.
This is for the release branch as well.

------------------------------------------

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.

Julien.

diff --git a/configure.ac b/configure.ac
index fab0809..384349f 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 fb004e2..f4eece5 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*)


More information about the reviews mailing list