]> gcc.gnu.org Git - gcc.git/commitdiff
Fortran: Fix problem with allocate initialization [PR99545].
authorPaul Thomas <pault@gcc.gnu.org>
Mon, 15 Mar 2021 09:32:52 +0000 (09:32 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Mon, 15 Mar 2021 11:10:41 +0000 (11:10 +0000)
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)

gcc/fortran/trans-stmt.c
gcc/testsuite/gfortran.dg/pr99545.f90 [new file with mode: 0644]

index 91e2689bce578f1e5257973a0f8a889da80dc031..d5aec5286fc4ed5bd509a06d1476279f191015a7 100644 (file)
@@ -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 (file)
index 0000000..1b5ed5d
--- /dev/null
@@ -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
This page took 0.081982 seconds and 5 git commands to generate.