]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fortran: fix reallocation on assignment of polymorphic variables [PR110415]
authorAndrew Jenner <andrew@codesourcery.com>
Tue, 28 Nov 2023 15:27:05 +0000 (15:27 +0000)
committerAndrew Jenner <andrew@codesourcery.com>
Tue, 28 Nov 2023 15:27:05 +0000 (15:27 +0000)
commitb247e917ff13328298c1eecf8563b12edd7ade04
tree4deaf6bf9094ceec5bd0f697ec2d825f08daf66d
parentf31a019d1161ec78846473da743aedf49cca8c27
Fortran: fix reallocation on assignment of polymorphic variables [PR110415]

This patch fixes two bugs related to polymorphic class assignment in the
Fortran front-end. One (described in PR110415) is an issue with the malloc
and realloc calls using the size from the old vptr rather than the new one.
The other is caused by the return value from the realloc call being ignored.
Testcases are added for these issues.

2023-11-28  Andrew Jenner  <andrew@codesourcery.com>

gcc/fortran/
PR fortran/110415
* trans-expr.cc (trans_class_vptr_len_assignment): Add
from_vptrp parameter. Populate it. Don't check for DECL_P
when deciding whether to create temporary.
(trans_class_pointer_fcn, gfc_trans_pointer_assignment): Add
NULL argument to trans_class_vptr_len_assignment calls.
(trans_class_assignment): Get rhs_vptr from
trans_class_vptr_len_assignment and use it for determining size
for allocation/reallocation. Use return value from realloc.

gcc/testsuite/
PR fortran/110415
* gfortran.dg/pr110415.f90: New test.
* gfortran.dg/asan/pr110415-2.f90: New test.
* gfortran.dg/asan/pr110415-3.f90: New test.

Co-Authored-By: Tobias Burnus <tobias@codesourcery.com>
gcc/fortran/trans-expr.cc
gcc/testsuite/gfortran.dg/asan/pr110415-2.f90 [new file with mode: 0755]
gcc/testsuite/gfortran.dg/asan/pr110415-3.f90 [new file with mode: 0755]
gcc/testsuite/gfortran.dg/pr110415.f90 [new file with mode: 0644]