Fortran: Fix problem with allocate initialization [PR99545].

2021-03-15  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran/ChangeLog

	PR fortran/99545
	* trans-stmt.c (gfc_trans_allocate): Mark the initialization
	assignment by setting init_flag.

gcc/testsuite/ChangeLog

	PR fortran/99545
	* gfortran.dg/pr99545.f90: New test.
This commit is contained in:
Paul Thomas 2021-03-15 09:32:52 +00:00
parent f20fe2cb21
commit 21ced2776a
2 changed files with 41 additions and 1 deletions

View File

@ -7001,7 +7001,7 @@ gfc_trans_allocate (gfc_code * code)
gfc_expr *init_expr = gfc_expr_to_initialize (expr);
gfc_expr *rhs = e3rhs ? e3rhs : gfc_copy_expr (code->expr3);
flag_realloc_lhs = 0;
tmp = gfc_trans_assignment (init_expr, rhs, false, false, true,
tmp = gfc_trans_assignment (init_expr, rhs, true, false, true,
false);
flag_realloc_lhs = realloc_lhs;
/* Free the expression allocated for init_expr. */

View File

@ -0,0 +1,40 @@
! { dg-do compile }
! { dg-options "-fcheck=mem" }
!
! Test the fix for PR99545, in which the allocate statements caused an ICE.
!
! Contributed by Juergen Reuter <juergen.reuter@desy.de>
!
module commands
implicit none
private
type, abstract :: range_t
integer :: step_mode = 0
integer :: n_step = 0
end type range_t
type, extends (range_t) :: range_int_t
integer :: i_step = 0
end type range_int_t
type, extends (range_t) :: range_real_t
real :: lr_step = 0
end type range_real_t
type :: cmd_scan_t
private
class(range_t), dimension(:), allocatable :: range
contains
procedure :: compile => cmd_scan_compile
end type cmd_scan_t
contains
subroutine cmd_scan_compile (cmd)
class(cmd_scan_t), intent(inout) :: cmd
allocate (range_int_t :: cmd%range (3))
allocate (range_real_t :: cmd%range (3))
end subroutine cmd_scan_compile
end module commands