Go to file
David Malcolm 14f5e56a8a analyzer: fix leak false +ve seen in haproxy's cfgparse.c [PR109059]
If a bound region gets overwritten with UNKNOWN due to being
possibly-aliased during a write, that could have been the only
region keeping its value live, in which case we could falsely report
a leak.  This is hidden somewhat by the "uncertainty" mechanism for
cases where the write happens in the same stmt as the last reference
to the value goes away, but not in the general case, which occurs
in PR analyzer/109059, which falsely complains about a leak whilst
haproxy updates a doubly-linked list.

The whole "uncertainty_t" class seems broken to me now; I think we need
to track (in the store) what values could have escaped to the external
part of the program.  We do this to some extent for pointers by tracking
the region as escaped, though we're failing to do this for this case:
even though there could still be other pointers to the region,
eventually they go away; we want to capture the fact that the external
part of the state is still keeping it live.  Also, this doesn't work for
non-pointer svalues, such as for detecting file-descriptor leaks.

As both a workaround and a step towards eventually removing
"class uncertainty_t" this patch updates the "mark_region_as_unknown"
code called by possibly-aliased set_value so that when old values are
removed, any base region pointed to them is marked as escaped, fixing
the leak false positive.

The patch has this effect on my integration tests of -fanalyzer:

  Comparison:
    GOOD: 129        (19.20% -> 20.22%)
     BAD: 543 -> 509 (-34)

where there's a big improvement in -Wanalyzer-malloc-leak:

  -Wanalyzer-malloc-leak:
    GOOD: 61       (45.19% -> 54.95%)
     BAD: 74 -> 50 (-24)
     Known false positives: 25 -> 2 (-23)
       haproxy-2.7.1: 24 ->  1 (-23)
     Suspected false positives: 49 -> 48 (-1)
       coreutils-9.1: 32 -> 31 (-1)

and some churn in the other warnings:

  -Wanalyzer-use-of-uninitialized-value:
     GOOD: 0
      BAD: 81 -> 80 (-1)
  -Wanalyzer-file-leak:
     GOOD: 0
      BAD: 10 -> 11 (+1)
  -Wanalyzer-out-of-bounds:
     GOOD: 0
      BAD: 24 -> 22 (-2)

gcc/analyzer/ChangeLog:
	PR analyzer/109059
	* region-model.cc (region_model::mark_region_as_unknown): Gather a
	set of maybe-live svalues and call on_maybe_live_values with it.
	* store.cc (binding_map::remove_overlapping_bindings): Add new
	"maybe_live_values" param; add any removed svalues to it.
	(binding_cluster::clobber_region): Add NULL as new param of
	remove_overlapping_bindings.
	(binding_cluster::mark_region_as_unknown): Add "maybe_live_values"
	param and pass it to remove_overlapping_bindings.
	(binding_cluster::maybe_get_compound_binding): Add NULL for new
	param of binding_map::remove_overlapping_bindings.
	(binding_cluster::remove_overlapping_bindings): Add
	"maybe_live_values" param and pass to
	binding_map::remove_overlapping_bindings.
	(store::set_value): Capture a set of maybe-live svalues, and call
	on_maybe_live_values with it.
	(store::on_maybe_live_values): New.
	(store::mark_region_as_unknown): Add "maybe_live_values" param
	and pass it to binding_cluster::mark_region_as_unknown.
	(store::remove_overlapping_bindings): Pass NULL for new param of
	binding_cluster::remove_overlapping_bindings.
	* store.h (binding_map::remove_overlapping_bindings): Add
	"maybe_live_values" param.
	(binding_cluster::mark_region_as_unknown): Likewise.
	(binding_cluster::remove_overlapping_bindings): Likewise.
	(store::mark_region_as_unknown): Likewise.
	(store::on_maybe_live_values): New decl.

gcc/testsuite/ChangeLog:
	PR analyzer/109059
	* gcc.dg/analyzer/flex-with-call-summaries.c: Remove xfail.
	* gcc.dg/analyzer/leak-pr109059-1.c: New test.
	* gcc.dg/analyzer/leak-pr109059-2.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-03-10 11:55:44 -05:00
INSTALL
c++tools Daily bump. 2023-01-10 00:18:07 +00:00
config Daily bump. 2022-11-15 08:32:29 +00:00
contrib Daily bump. 2023-02-23 00:17:57 +00:00
fixincludes Daily bump. 2023-02-18 00:17:20 +00:00
gcc analyzer: fix leak false +ve seen in haproxy's cfgparse.c [PR109059] 2023-03-10 11:55:44 -05:00
gnattools Daily bump. 2022-09-01 00:17:39 +00:00
gotools Daily bump. 2022-08-31 00:16:45 +00:00
include Daily bump. 2023-02-28 00:18:40 +00:00
intl Daily bump. 2022-11-24 00:17:47 +00:00
libada Update copyright years. 2023-01-16 11:52:17 +01:00
libatomic Daily bump. 2023-03-04 00:16:30 +00:00
libbacktrace Daily bump. 2023-01-21 00:16:20 +00:00
libcc1 Update copyright years. 2023-01-16 11:52:17 +01:00
libcody Update Copyright year in ChangeLog files 2023-01-02 09:23:36 +01:00
libcpp Daily bump. 2023-03-01 00:18:20 +00:00
libdecnumber Update copyright years. 2023-01-16 11:52:17 +01:00
libffi Daily bump. 2023-01-23 00:16:34 +00:00
libgcc Daily bump. 2023-03-09 00:17:00 +00:00
libgfortran Daily bump. 2023-03-01 00:18:20 +00:00
libgm2 Daily bump. 2023-02-28 00:18:40 +00:00
libgo libgo: revert incorrectly committed change 2023-03-05 20:01:56 -08:00
libgomp Allow libgomp 'cbuf' buffering with OpenACC 'async' for 'ephemeral' data 2023-03-10 16:19:53 +01:00
libiberty Daily bump. 2023-03-04 00:16:30 +00:00
libitm Update copyright years. 2023-01-16 11:52:17 +01:00
libobjc Update copyright years. 2023-01-16 11:52:17 +01:00
libphobos Daily bump. 2023-02-22 00:18:49 +00:00
libquadmath Daily bump. 2023-03-03 00:16:38 +00:00
libsanitizer libsanitizer: cherry-pick commit 8f5962b1ccb5fcd4d4544121d43efb860ac3cc6d from upstream 2023-02-24 09:14:40 +01:00
libssp Update copyright years. 2023-01-16 11:52:17 +01:00
libstdc++-v3 libstdc++: Fix GDB Xmethod for std::shared_ptr::use_count() [PR109064] 2023-03-10 11:10:23 +00:00
libvtv Update copyright years. 2023-01-16 11:52:17 +01:00
lto-plugin Update copyright years. 2023-01-16 11:52:17 +01:00
maintainer-scripts Daily bump. 2022-12-01 00:17:51 +00:00
zlib Daily bump. 2022-11-24 00:17:47 +00:00
.dir-locals.el dir-locals: Use https for bug references 2021-07-20 11:40:34 +01:00
.gitattributes
.gitignore .gitignore: do not ignore config.h 2022-07-19 17:07:04 +03:00
ABOUT-NLS
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
ChangeLog Daily bump. 2023-02-17 00:17:49 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
MAINTAINERS MAINTAINERS: stepping down from my positions 2023-02-16 16:50:38 +01:00
Makefile.def configure: Do not build the ununsed libffi shared library. 2022-12-31 17:51:47 +00:00
Makefile.in configure: Do not build the ununsed libffi shared library. 2022-12-31 17:51:47 +00:00
Makefile.tpl Merge modula-2 front end onto gcc. 2022-12-14 17:43:08 +00:00
README
ar-lib
compile
config-ml.in
config.guess
config.rpath
config.sub config.sub: change mode to 755. 2021-12-21 09:10:57 +01:00
configure configure: remove dependencies on gmp and mpfr when gdb is disabled 2023-01-06 09:36:52 +01:00
configure.ac configure: remove dependencies on gmp and mpfr when gdb is disabled 2023-01-06 09:36:52 +01:00
depcomp
install-sh
libtool-ldflags
libtool.m4 Generic configury support for shared libs on VxWorks 2022-10-11 07:31:07 +00:00
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
symlink-tree
test-driver
ylwrap

README

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.