PR fortran/98661 - valgrind issues with error recovery
authorHarald Anlauf <anlauf@gmx.de>
Thu, 14 Jan 2021 18:21:05 +0000 (19:21 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Thu, 14 Jan 2021 18:21:05 +0000 (19:21 +0100)
During error recovery after an invalid derived type specification it was
possible to try to resolve an invalid array specification.  We now skip
this if the component has the ALLOCATABLE or POINTER attribute and the
shape is not deferred.

gcc/fortran/ChangeLog:

PR fortran/98661
* resolve.c (resolve_component): Derived type components with
ALLOCATABLE or POINTER attribute shall have a deferred shape.

gcc/testsuite/ChangeLog:

PR fortran/98661
* gfortran.dg/pr98661.f90: New test.

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

index f243bd185b014b6dafc79b096485eef9dcd0fad5..ab7ffc2c8b64d741d53b06932a16167a01910dfa 100644 (file)
@@ -14723,6 +14723,10 @@ resolve_component (gfc_component *c, gfc_symbol *sym)
         && sym != c->ts.u.derived)
     add_dt_to_dt_list (c->ts.u.derived);
 
+  if (c->as && c->as->type != AS_DEFERRED
+      && (c->attr.pointer || c->attr.allocatable))
+    return false;
+
   if (!gfc_resolve_array_spec (c->as,
                                !(c->attr.pointer || c->attr.proc_pointer
                                  || c->attr.allocatable)))
diff --git a/gcc/testsuite/gfortran.dg/pr98661.f90 b/gcc/testsuite/gfortran.dg/pr98661.f90
new file mode 100644 (file)
index 0000000..40ddff0
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do compile }
+! PR fortran/98661 - valgrind issues with error recovery
+!
+! Test issues related to former testcase charlen_03.f90
+program p
+  implicit none
+  type t
+     character(:), pointer :: c(n) ! { dg-error "must have a deferred shape" }
+     real,     allocatable :: x(n) ! { dg-error "must have a deferred shape" }
+  end type
+end
+
+subroutine s
+! no 'implicit none'
+  type u
+     character(:), pointer :: c(n) ! { dg-error "must have a deferred shape" }
+     real,     allocatable :: x(n) ! { dg-error "must have a deferred shape" }
+  end type
+end