https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127714
Bug ID: 127714
Summary: Bogus out-of-bounds on character arrays
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: ---
The domain of character arrays in Fortran starts at 1 which is currently not
correctly handled in the analyzer. This results in a bogus out-of-bounds
warning followed by an internal compiler error.
function chars(n) result(r)
integer, intent(in) :: n
character(:), allocatable :: r
r = repeat('a', n)
end function
$ 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:20:
4 | r = repeat('a', n)
| ^
Warning: buffer over-read [CWE-126] [-Wanalyzer-out-of-bounds]
‘chars’: event 1
4 | r = repeat('a', n)
| ^
| |
| (1) following ‘false’ branch... ─>─┐
| │
‘chars’: events 2-3
| │
|┌────────────────────────────────────────┘
4 |│ r = repeat('a', n)
|│ ^
|│ |
|└──────────────────>(2) ...to here
| (3) ⚠️ out-of-bounds read at byte 1 but ‘"a"’ ends
at byte 1
test.f90:4:20: note: read of 1 byte from after the end of ‘"a"’
test.f90:4:20: note: valid subscripts for ‘"a"’ are ‘[1]’ to ‘[1]’
during IPA pass: analyzer
test.f90:5:12:
5 | end function
| ^
internal compiler error: in set_cell_span, at text-art/table.cc:146
/usr/libexec/gcc/x86_64-redhat-linux/16/f951 test.f90 -quiet -dumpbase test.f90
-dumpbase-ext .f90 -mtune=generic -march=x86-64 -mtls-dialect=gnu2 -fanalyzer
-fintrinsic-modules-path /usr/lib/gcc/x86_64-redhat-linux/16/finclude
-fpre-include=/usr/include/finclude/math-vector-fortran.h -o /tmp/ccM9A4GH.s
Please submit a full bug report, with preprocessed source.
See <https://bugzilla.redhat.com/> for instructions.