https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104821

            Bug ID: 104821
           Summary: RFE: consolidate analyzer leak diagnostics by
                    considering indirect vs direct leaks
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
  Target Milestone: ---

PR analyzer/101983 reports a pair of -Wanalyzer-malloc-leak warnings at the
same program point, where both:
  *res
and
  *(res->a)
are leaked.

This is a common case where we have a direct leak (of '*res'), leading to
indirect leaks of the things *res is pointing to (of '*(res->a)').

Currently we emit all of these leak warnings, and don't distinguish between
them.

Idea: report the direct leaks, and consolidate all of indirect leaks as notes
on the direct leaks:

e.g. 
  warning: leak of 'ptr'
  [...execution path here...]
  note: direct leak of 'ptr' leads to indirect leak of 'ptr->foo'
  [...execution path here?  or just show the allocation point of 'ptr->foo']
  note: indirect leak of 'ptr->foo' leads to indirect leak of 'ptr->foo->bar'
  [...etc...]

where we can envisage a tree structure of leaks that are reponsible for other
leaks.  We could even visualize this tree with ASCII art, showing the subgraph
of objects and where it becomes unreachable.

Doing so could reduce the verbosity of the analyzer, making the report to the
end-user a little "higher-level".

Reply via email to