Dear all,

the former Fortran testcase charlen_03.f90, which some time ago used to
ICE, could still display issues during error recovery.  As Dominique
pointed out, this required either an instrumented compiler, or valgrind.

The issue turned out to not have anything to do with CHARACTER, but
with an invalid attempt resolve an invalid array specification.

Regtested on x86_64-pc-linux-gnu, and checked for the testcase with valgrind.

OK for master?

Thanks,
Harald


PR fortran/98661 - valgrind issues with error recovery

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.

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 3929ddff849..448a2362e95 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -14723,6 +14735,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
index 00000000000..40ddff05d43
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr98661.f90
@@ -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

Reply via email to