https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124666
Bug ID: 124666
Summary: [16 Regression] [UBSAN] io.cc:290:27: runtime error:
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: dcb314 at hotmail dot com
Target Milestone: ---
The following F90 code
integer ::n_part(10)=1
write(1,'(32767(tr1,i0))') n_part
write(1,'(32768(tr1,i0))') n_part
write(1,'(1000000(tr1,i0))') n_part
write(1,'(2147483647(tr1,i0))') n_part
print *,'pass'
end
when compiled by 15.2.0, is fine:
$ ~/gcc/results.15.2.0/bin/gfortran -c -w trunk/Fortran/0486/0486_0274.f08
$
Recent gcc trunk with UBSAN seems less happy with it:
$ fortran -c -w trunk/Fortran/0486/0486_0274.f08
dcb@raspberrypi:~/fujitsu $ ~/gcc/results/bin/gfortran -c -w
trunk/Fortran/0486/0486_0274.f08
../../trunk/gcc/fortran/io.cc:290:27: runtime error: signed integer overflow:
55 + 2147483640 cannot be represented in type 'int'
#0 0x0050e858 in format_lex ../../trunk/gcc/fortran/io.cc:290
#1 0x0050e858 in format_lex ../../trunk/gcc/fortran/io.cc:222
#2 0x0050f584 in check_format ../../trunk/gcc/fortran/io.cc:628
I had a quick look at the compiler source code and found:
do
{
c = next_char_not_space ();
if (ISDIGIT (c))
{
value = 10 * value + c - '0';
if (c != '0')
zflag = 0;
}
}
while (ISDIGIT (c));
Presumably there is some good reason why a library routine
like strtoul could not be used.