[gcc r9-9284] Fortran: Fix problem with allocate initialization [PR99545].

Paul Thomas pault@gcc.gnu.org
Mon Mar 15 12:09:46 GMT 2021


https://gcc.gnu.org/g:b4f86a21263b8e731de68a78862e5c480ef3d160

commit r9-9284-gb4f86a21263b8e731de68a78862e5c480ef3d160
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Mon Mar 15 09:32:52 2021 +0000

    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.
    
    (cherry picked from commit 21ced2776a117924e52f6aab8b41afb613fef0e7)

Diff:
---
 gcc/fortran/trans-stmt.c              |  2 +-
 gcc/testsuite/gfortran.dg/pr99545.f90 | 40 +++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 91e2689bce5..d5aec5286fc 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -6628,7 +6628,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 00000000000..1b5ed5da29b
--- /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  <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


More information about the Gcc-cvs mailing list