Gcc has an -fanalyzer option for static analysis, (added by a developer at Red Hat in 2020) as does gfortran. Does anyone use if for Fortran code or for C code? I tried it on one of my Fortran source files (5600 lines), and it slowed the compilation dramatically, from 1.3s without to 54s with the -fanalyzer option. The documentation does say “This analysis is much more expensive than other GCC warnings.” Gfortran -c -fanalyzer statistics.f90
said
statistics.f90:338:0:
338 | if (size(ix) /= size(xx)) return
|
Warning: leak of 'istat.0_92' [CWE-401] [-Wanalyzer-malloc-leak]
'stat_categories_many_str': events 1-3
|
| 344 | function stat_categories_many_str(cstat,ncat,ix,xx) result(yy)
| |
|......
| 350 | yy = stat_categories_many(istat_str(cstat),ncat,ix,xx)
| |
|
+--> 'stat_categories_many': events 4-7
|
| 330 | function stat_categories_many(istat,ncat,ix,xx) result(yy)
| |
|......
| 338 | if (size(ix) /= size(xx)) return
| |
|
for the subroutine
function stat_categories_many(istat,ncat,ix,xx) result(yy)
integer , intent(in) :: istat(:)
integer , intent(in) :: ncat
integer , intent(in) :: ix(:)
real(kind=dp), intent(in) :: xx(:)
real(kind=dp) :: yy(size(istat),ncat)
integer :: i
yy = 0.0_dp
if (size(ix) /= size(xx)) return
do i=1,ncat
yy(:,i) = stat_vec_int_many(istat,pack(xx,ix==i))
end do
end function stat_categories_many
I don’t see anything wrong with the code.