From 21ced2776a117924e52f6aab8b41afb613fef0e7 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Mon, 15 Mar 2021 09:32:52 +0000 Subject: [PATCH] Fortran: Fix problem with allocate initialization [PR99545]. 2021-03-15 Paul Thomas 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. --- gcc/fortran/trans-stmt.c | 2 +- gcc/testsuite/gfortran.dg/pr99545.f90 | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr99545.f90 diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 547468f..7cbdef7 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -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. */ diff --git a/gcc/testsuite/gfortran.dg/pr99545.f90 b/gcc/testsuite/gfortran.dg/pr99545.f90 new file mode 100644 index 0000000..1b5ed5d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr99545.f90 @@ -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 +! +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 -- 2.7.4