]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: ICE, OOM while calculating sizes of derived type array components
authorHarald Anlauf <anlauf@gmx.de>
Wed, 21 Jul 2021 16:54:00 +0000 (18:54 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Wed, 21 Jul 2021 16:54:00 +0000 (18:54 +0200)
gcc/fortran/ChangeLog:

PR fortran/101514
* target-memory.c (gfc_interpret_derived): Size of array component
of derived type can only be computed here for explicit shape.
* trans-types.c (gfc_get_nodesc_array_type): Do not dereference
NULL pointers.

gcc/testsuite/ChangeLog:

PR fortran/101514
* gfortran.dg/pr101514.f90: New test.

gcc/fortran/target-memory.c
gcc/fortran/trans-types.c
gcc/testsuite/gfortran.dg/pr101514.f90 [new file with mode: 0644]

index cfa8402dd3f6e2ab391913f36627279c8f48c9e1..7b21a9e04e8b375bc0327259bcc2a2db59d775bd 100644 (file)
@@ -534,6 +534,9 @@ gfc_interpret_derived (unsigned char *buffer, size_t buffer_size, gfc_expr *resu
        {
          int n;
 
+         if (cmp->as->type != AS_EXPLICIT)
+           return 0;
+
          e->expr_type = EXPR_ARRAY;
          e->rank = cmp->as->rank;
 
index d715838a0463167cadea458eebc4dba4fa785571..50fda4328f788219ccefcc87f8ed31e46df43e4f 100644 (file)
@@ -1644,7 +1644,7 @@ gfc_get_nodesc_array_type (tree etype, gfc_array_spec * as, gfc_packed packed,
       GFC_TYPE_ARRAY_STRIDE (type, n) = tmp;
 
       expr = as->lower[n];
-      if (expr->expr_type == EXPR_CONSTANT)
+      if (expr && expr->expr_type == EXPR_CONSTANT)
         {
           tmp = gfc_conv_mpz_to_tree (expr->value.integer,
                                      gfc_index_integer_kind);
@@ -1694,7 +1694,7 @@ gfc_get_nodesc_array_type (tree etype, gfc_array_spec * as, gfc_packed packed,
   for (n = as->rank; n < as->rank + as->corank; n++)
     {
       expr = as->lower[n];
-      if (expr->expr_type == EXPR_CONSTANT)
+      if (expr && expr->expr_type == EXPR_CONSTANT)
        tmp = gfc_conv_mpz_to_tree (expr->value.integer,
                                    gfc_index_integer_kind);
       else
diff --git a/gcc/testsuite/gfortran.dg/pr101514.f90 b/gcc/testsuite/gfortran.dg/pr101514.f90
new file mode 100644 (file)
index 0000000..51fbf8a
--- /dev/null
@@ -0,0 +1,35 @@
+! { dg-do compile }
+! PR fortran/101514 - ICE: out of memory allocating ... bytes
+
+subroutine s
+  type t1
+     integer :: a(..) ! { dg-error "must have an explicit shape" }
+  end type
+  type t2
+     integer :: a(*)  ! { dg-error "must have an explicit shape" }
+  end type
+  type t3
+     integer :: a(:)  ! { dg-error "must have an explicit shape" }
+  end type
+  type t4
+     integer :: a(0:) ! { dg-error "must have an explicit shape" }
+  end type
+  type t5
+     integer, allocatable :: a(:)
+  end type
+  type t6
+     integer, pointer     :: a(:)
+  end type
+  type(t1) :: a1
+  type(t2) :: a2
+  type(t3) :: a3
+  type(t4) :: a4
+  type(t5) :: a5
+  type(t6) :: a6
+  a1 = transfer(1, a1)
+  a2 = transfer(1, a2)
+  a3 = transfer(1, a3)
+  a4 = transfer(1, a4)
+  a5 = transfer(1, a5)
+  a6 = transfer(1, a6)
+end