]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/82934 (Segfault on assumed character length in allocate)
authorPaul Thomas <pault@gcc.gnu.org>
Tue, 14 Nov 2017 17:38:38 +0000 (17:38 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Tue, 14 Nov 2017 17:38:38 +0000 (17:38 +0000)
2017-11-13  Paul Thomas  <pault@gcc.gnu.org>

Backport from trunk
PR fortran/82934
* trans-stmt.c (gfc_trans_allocate): Remove the gcc_assert on
null string length for assumed length typespec and set
expr3_esize to NULL_TREE;

2017-11-13  Paul Thomas  <pault@gcc.gnu.org>

Backport from trunk
PR fortran/82934
* gfortran.dg/allocate_assumed_charlen_1.f90: New test.

From-SVN: r254733

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

index 603ed33fc3a4819163a6fd47c697bf54062d1cac..f278002b90a215c5f3885c1e04c71290bcb32569 100644 (file)
@@ -1,3 +1,11 @@
+2017-11-13  Paul Thomas  <pault@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/82934
+       * trans-stmt.c (gfc_trans_allocate): Remove the gcc_assert on
+       null string length for assumed length typespec and set
+       expr3_esize to NULL_TREE;
+
 2017-11-13  Paul Thomas  <pault@gcc.gnu.org>
 
        Backport from trunk
index d18e21bdc26eea27daccfcefa2e4777e9ebb0070..45510bc51f73d2b3dc2fb21a6a7bdda374d576c8 100644 (file)
@@ -5693,10 +5693,9 @@ gfc_trans_allocate (gfc_code * code)
       if (code->ext.alloc.ts.type != BT_CHARACTER)
        expr3_esize = TYPE_SIZE_UNIT (
              gfc_typenode_for_spec (&code->ext.alloc.ts));
-      else
+      else if (code->ext.alloc.ts.u.cl->length != NULL)
        {
          gfc_expr *sz;
-         gcc_assert (code->ext.alloc.ts.u.cl->length != NULL);
          sz = gfc_copy_expr (code->ext.alloc.ts.u.cl->length);
          gfc_init_se (&se_sz, NULL);
          gfc_conv_expr (&se_sz, sz);
@@ -5710,6 +5709,8 @@ gfc_trans_allocate (gfc_code * code)
                                         tmp, se_sz.expr);
          expr3_esize = gfc_evaluate_now (expr3_esize, &block);
        }
+      else
+       expr3_esize = NULL_TREE;
     }
 
   /* Loop over all objects to allocate.  */
index fd9561b184c89a3e0cb707a934e7d5707393034c..df7913a0ae416ab658e67e73f640d5027a573339 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-13  Paul Thomas  <pault@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/82934
+       * gfortran.dg/allocate_assumed_charlen_1.f90: New test.
+
 2017-11-13  Paul Thomas  <pault@gcc.gnu.org>
 
        Backport from trunk
diff --git a/gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90 b/gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90
new file mode 100644 (file)
index 0000000..382df36
--- /dev/null
@@ -0,0 +1,28 @@
+! { dg-do run }
+!
+! PR82934: Segfault on compilation in trans-stmt.c:5919(8.0.0).
+! The original report only had one item in the allocate list. This
+! has been doubled up to verify that the correct string length is
+! is used in the allocation.
+!
+! Contributed by FortranFan on clf.
+!
+   character(len=42), allocatable :: foo
+   character(len=22), allocatable :: foofoo
+
+   call alloc( foo , foofoo)
+
+   if (len(foo) .ne. 42) call abort
+   if (len(foofoo) .ne. 22) call abort
+
+contains
+
+   subroutine alloc( bar, barbar )
+
+      character(len=*), allocatable :: bar, barbar
+
+      allocate( character(len=*) :: bar , barbar) ! <= Here!
+
+   end subroutine
+
+end