]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/82367 (ICE with deferred length string allocate on non-deferred length...
authorSteven G. Kargl <kargl@gcc.gnu.org>
Wed, 10 Jan 2018 23:55:00 +0000 (23:55 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Wed, 10 Jan 2018 23:55:00 +0000 (23:55 +0000)
2018-01-10  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/82367
* resolve.c (resolve_allocate_expr): Check for NULL pointer.

2018-01-10  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/82367
* gfortran.dg/deferred_character_18.f90: New test.

From-SVN: r256467

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/deferred_character_18.f90 [new file with mode: 0644]

index 095b1bb7a15eff726a5f23702f8b1342b69e4fbb..cd2be3fecdcceaaec5cc8b15c6a228a9bb222ca6 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-10  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/82367
+       * resolve.c (resolve_allocate_expr): Check for NULL pointer.
+
 2018-01-10 Steven G. Kargl  <kargl@gcc.gnu.org>
 
        Backport from trunk
index 222fb7854c4a5fd27e310f99da39aa0c7bf1719a..ef938009f755d8331c39364b372ede74dd7d5f2b 100644 (file)
@@ -7136,8 +7136,13 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool *array_alloc_wo_spec)
   if (code->ext.alloc.ts.type == BT_CHARACTER && !e->ts.deferred
       && !UNLIMITED_POLY (e))
     {
-      int cmp = gfc_dep_compare_expr (e->ts.u.cl->length,
-                                     code->ext.alloc.ts.u.cl->length);
+      int cmp;
+
+      if (!e->ts.u.cl->length)
+       goto failure;
+
+      cmp = gfc_dep_compare_expr (e->ts.u.cl->length,
+                                 code->ext.alloc.ts.u.cl->length);
       if (cmp == 1 || cmp == -1 || cmp == -3)
        {
          gfc_error ("Allocating %s at %L with type-spec requires the same "
index 9304367256ada6580b3033865e78bdf6f1b154a3..300e93dcf504dc3bcf4b365d42c74907de571d3a 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-10  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/82367
+       * gfortran.dg/deferred_character_18.f90: New test.
+
 2018-01-10  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        Backport from trunk
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_18.f90 b/gcc/testsuite/gfortran.dg/deferred_character_18.f90
new file mode 100644 (file)
index 0000000..1b1457f
--- /dev/null
@@ -0,0 +1,29 @@
+! { dg-do compile }
+! PR Fortran/82367
+! Contributed by Walter Spector <w6ws at earthlink dot net>
+module cls_allocmod
+  implicit none
+
+contains
+
+ subroutine cls_alloc (n, str)
+    integer,  intent(in) :: n
+    character(*), allocatable, intent(out) :: str
+!  Note: Star ^ should have been a colon (:)
+
+    allocate (character(n)::str)
+
+  end subroutine
+
+end module
+
+program cls
+  use cls_allocmod
+  implicit none
+
+  character(:), allocatable :: s
+
+  call cls_alloc(42, s) ! { dg-error "allocatable or pointer dummy argument" }
+  print *, 'string len =', len(s)
+
+end program