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

            Bug ID: 127715
           Summary: Fortran: Analyzer reports internal branches
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: henri at henrimenke dot de
  Target Milestone: ---

Currently the analyzer reports various internal branches that are taken when
leaking memory from the allocate statement. While harmless, the information
about internal fields like a.data and following invisible false branches is
confusing.



program leak
  integer, allocatable :: a(:)
  allocate(a(1:10))
end program leak



$ gfortran --version
GNU Fortran (GCC) 16.2.1 20260819 (Red Hat 16.2.1-2)
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gfortran -fanalyzer -c test.f90
test.f90:4:16:

    4 | end program leak
      |                ^
Warning: leak of ‘a.data’ [CWE-401] [-Wanalyzer-malloc-leak]
  ‘leak’: event 1
    3 |   allocate(a(1:10))
      |                   ^
      |                   |
      |                   (1) following ‘false’ branch... ─>─┐
      |                                                      │
  ‘leak’: events 2-5
      |                                                      │
      |┌─────────────────────────────────────────────────────┘
    3 |│  allocate(a(1:10))
      |│                  ^
      |│                  |
      |└─────────────────>(2) ...to here
      |                   (3) allocated here
      |                   (4) assuming ‘a.data’ is non-NULL
      |                   (5) following ‘false’ branch... ─>─┐
      |                                                      │
  ‘leak’: events 6-7
      |                                                      │
      |┌─────────────────────────────────────────────────────┘
    3 |│  allocate(a(1:10))
      |│                  ^
      |│                  |
      |└─────────────────>(6) ...to here
    4 | end program leak
      |                ~   
      |                |
      |                (7) ⚠️   ‘a.data’ leaks here; was allocated at (3)

Reply via email to