]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fortran: ALLOCATE of fixed-length CHARACTER with SOURCE/MOLD [PR113793]
authorHarald Anlauf <anlauf@gmx.de>
Sat, 13 Apr 2024 17:09:24 +0000 (19:09 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 16 Apr 2024 16:40:56 +0000 (18:40 +0200)
commit48024a99e3c2ae522d0026eedd591390506b68ca
treec923acf0e16dd5dd684fae7ae85f086b183cc540
parent443748259d903b6f4d4557392fc788df93d63377
Fortran: ALLOCATE of fixed-length CHARACTER with SOURCE/MOLD [PR113793]

F2008 requires for ALLOCATE with SOURCE= or MOLD= specifier that the kind
type parameters of allocate-object and source-expr have the same values.
Add compile-time diagnostics for different character length and a runtime
check (under -fcheck=bounds).  Use length from allocate-object to prevent
heap corruption and to allow string padding or truncation on assignment.

gcc/fortran/ChangeLog:

PR fortran/113793
* resolve.cc (resolve_allocate_expr): Reject ALLOCATE with SOURCE=
or MOLD= specifier for unequal length.
* trans-stmt.cc (gfc_trans_allocate): If an allocatable character
variable has fixed length, use it and do not use the source length.
With bounds-checking enabled, add a runtime check for same length.

gcc/testsuite/ChangeLog:

PR fortran/113793
* gfortran.dg/allocate_with_source_29.f90: New test.
* gfortran.dg/allocate_with_source_30.f90: New test.
* gfortran.dg/allocate_with_source_31.f90: New test.
gcc/fortran/resolve.cc
gcc/fortran/trans-stmt.cc
gcc/testsuite/gfortran.dg/allocate_with_source_29.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/allocate_with_source_30.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/allocate_with_source_31.f90 [new file with mode: 0644]