]> gcc.gnu.org Git - gcc.git/commit
analyzer: fix overzealous state purging with on-stack structs [PR108704]
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 8 Feb 2023 18:47:36 +0000 (13:47 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 8 Feb 2023 18:47:36 +0000 (13:47 -0500)
commit77bb54b1b07add45007c664724b726541d672ef3
tree99263fef9122f4abc105a68181d03fa293fb09e5
parent2eeda82d6288fb2a8fbc302d98ed51337e01aaaa
analyzer: fix overzealous state purging with on-stack structs [PR108704]

PR analyzer/108704 reports many false positives seen from
-Wanalyzer-use-of-uninitialized-value on qemu's softfloat.c on code like
the following:

   struct st s;
   s = foo ();
   s = bar (s); // bogusly reports that s is uninitialized here

where e.g. "struct st" is "floatx80" in the qemu examples.

The root cause is overzealous purging of on-stack structs in the code I
added in r12-7718-gfaacafd2306ad7, where at:

s = bar (s);

state_purge_per_decl::process_point_backwards "sees" the assignment to 's'
and stops processing, effectively treating 's' as unneeded before this
stmt, not noticing the use of 's' in the argument.

Fixed thusly.

The patch greatly reduces the number of
-Wanalyzer-use-of-uninitialized-value warnings from my integration tests:
  ImageMagick-7.1.0-57:  10 ->  6   (-4)
              qemu-7.2: 858 -> 87 (-771)
         haproxy-2.7.1:   1 ->  0   (-1)
All of the above that I've examined appear to be false positives.

gcc/analyzer/ChangeLog:
PR analyzer/108704
* state-purge.cc (state_purge_per_decl::process_point_backwards):
Don't stop processing the decl if it's fully overwritten by
this stmt if it's also used by this stmt.

gcc/testsuite/ChangeLog:
PR analyzer/108704
* gcc.dg/analyzer/uninit-7.c: New test.
* gcc.dg/analyzer/uninit-pr108704.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/state-purge.cc
gcc/testsuite/gcc.dg/analyzer/uninit-7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/analyzer/uninit-pr108704.c [new file with mode: 0644]
This page took 0.072154 seconds and 6 git commands to generate.