diff mbox series

PR fortran/98661 - valgrind issues with error recovery

Message ID trinity-8349abeb-9b37-4f27-9166-02de88fd17fe-1610573087712@3c-app-gmx-bap27
State New
Headers show
Series PR fortran/98661 - valgrind issues with error recovery | expand

Commit Message

Harald Anlauf Jan. 13, 2021, 9:24 p.m. UTC
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.

Comments

Paul Richard Thomas Jan. 14, 2021, 6:05 p.m. UTC | #1
Hi Harald,

That's OK for master.

Thanks

Paul


On Wed, 13 Jan 2021 at 21:25, Harald Anlauf via Fortran <fortran@gcc.gnu.org>
wrote:

> 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 mbox series

Patch

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