On 21/05/2020 13:29, Pádraig Brady wrote:
On 21/05/2020 01:49, Paul Eggert wrote:
The coreutils patch installed on May 10 to pacify GCC 10 -fanalyzer
caused problems when I built coreutils with GCC 10.1.0. Some of the
newly-introduced pragmas generated diagnostics, and the pragmas didn't
seem to be needed in GCC 10.1.0 anyway. As 10.1.0 is the first public
release of GCC 10 I doubt whether we need to support GCC internal
versions (before GCC 10.1.0) that had problems with -fanalyze.

Also, the patch seems to have introduced a bug in tsort.c due to a typo.
Less importantly, it introduced some new overhead in dd.c's non-lint
code (to save some pointers in global variables) that isn't needed and
might cause problems with other static checkers.

To try to fix all this I installed the attached patches.

At some point I hope this GCC 10 stuff settles down, as GCC 10.1.0 still
has bugs in the -fanalyzer area (e.g., see GCC bugs 93644, 95044, 95072)
and we don't want these bugs to adversely affect coreutils etc.

Previously I was testing with the first Fedora 32 (public) GCC:
    gcc (GCC) 10.0.1 20200328 (Red Hat 10.0.1-0.11)

After just upgrading:
    sudo dnf upgrade --advisory=FEDORA-2020-2c6c85202d
    gcc (GCC) 10.1.1 20200507 (Red Hat 10.1.1-1)

I can confirm that the comm.c pragma causes issues for gcc 10.1
    src/comm.c:21:33: error: unknown option after '#pragma GCC diagnostic' kind 
[-Werror=pragmas]
     21 | # pragma GCC diagnostic ignored 
"-Wanalyzer-use-of-uninitialized-value"

The good news is that this is no longer needed to suppress
-fanalyzer warnings, so we can just remove it.

The other pragmas are still needed though to suppress -fanalyzer warnings.

Also the dd change has minimal overhead and makes valgrind output cleaner.

Oh I see you improved the dd change, rather than remove it.

The attached patch on latest suppresses all warnings.
I also see with the latest gnulib that I also need to
pass -Wno-analyzer-too-complex to avoid very many such warnings.

cheers,
Pádraig
>From 78988e6604ed05dfe6c7755f070d8fda69a9d36d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Thu, 21 May 2020 13:45:01 +0100
Subject: [PATCH] maint: avoid warnings from GCC's -fanalyzer

Reinstate a couple of -fanalyzer warning suppressions
from commit v8.32-10-gc7194b43f, needed with Fedora 32:
gcc (GCC) 10.1.1 20200507 (Red Hat 10.1.1-1)

* src/tsort.c (record_relation): An assert doesn't suffice to avoid:
  [CWE-690] [-Wanalyzer-null-dereference]
so disable the warning for this function.
* src/chown-core.c: Suppress the following false positive for the file:
  [CWE-415] [-Wanalyzer-double-free]
---
 src/chown-core.c |  5 +++++
 src/tsort.c      | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/src/chown-core.c b/src/chown-core.c
index f1e37eb26..6c221d287 100644
--- a/src/chown-core.c
+++ b/src/chown-core.c
@@ -16,6 +16,11 @@
 
 /* Extracted from chown.c/chgrp.c and librarified by Jim Meyering.  */
 
+/* GCC 10 gives a false postive warning with -fanalyzer for this.  */
+#if (__GNUC__ == 10 && 0 <= __GNUC_MINOR__) || 10 < __GNUC__
+# pragma GCC diagnostic ignored "-Wanalyzer-double-free"
+#endif
+
 #include <config.h>
 #include <stdio.h>
 #include <sys/types.h>
diff --git a/src/tsort.c b/src/tsort.c
index 2a6961aa7..8373ca161 100644
--- a/src/tsort.c
+++ b/src/tsort.c
@@ -274,6 +274,13 @@ record_relation (struct item *j, struct item *k)
 {
   struct successor *p;
 
+/* GCC 10 gives a false postive warning with -fanalyzer for this,
+   and an assert did not suppress the warning
+   with the initial GCC 10 release.  */
+#if (__GNUC__ == 10 && 0 <= __GNUC_MINOR__) || 10 < __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wanalyzer-null-dereference"
+#endif
   if (!STREQ (j->str, k->str))
     {
       k->count++;
@@ -282,6 +289,9 @@ record_relation (struct item *j, struct item *k)
       p->next = j->top;
       j->top = p;
     }
+#if (__GNUC__ == 10 && 0 <= __GNUC_MINOR__) || 10 < __GNUC__
+# pragma GCC diagnostic pop
+#endif
 }
 
 static bool
-- 
2.26.2

Reply via email to