public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1757] Fortran: error recovery on invalid array reference of non-array [PR103590]
@ 2022-07-19 21:28 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-07-19 21:28 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f838d15641d256e21ffc126c3277b290ed743928

commit r13-1757-gf838d15641d256e21ffc126c3277b290ed743928
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Jul 18 22:34:53 2022 +0200

    Fortran: error recovery on invalid array reference of non-array [PR103590]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/103590
            * resolve.cc (find_array_spec): Change function result to bool to
            enable error recovery.  Generate error message for invalid array
            reference of non-array entity instead of an internal error.
            (gfc_resolve_ref): Use function result from find_array_spec for
            error recovery.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/103590
            * gfortran.dg/associate_54.f90: Adjust.
            * gfortran.dg/associate_59.f90: New test.

Diff:
---
 gcc/fortran/resolve.cc                     | 13 ++++++++++---
 gcc/testsuite/gfortran.dg/associate_54.f90 |  3 +--
 gcc/testsuite/gfortran.dg/associate_59.f90 |  9 +++++++++
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 2ebf076f730..ca114750f65 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -4976,7 +4976,7 @@ gfc_resolve_dim_arg (gfc_expr *dim)
 static void
 resolve_assoc_var (gfc_symbol* sym, bool resolve_target);
 
-static void
+static bool
 find_array_spec (gfc_expr *e)
 {
   gfc_array_spec *as;
@@ -5004,7 +5004,11 @@ find_array_spec (gfc_expr *e)
       {
       case REF_ARRAY:
 	if (as == NULL)
-	  gfc_internal_error ("find_array_spec(): Missing spec");
+	  {
+	    gfc_error ("Invalid array reference of a non-array entity at %L",
+		       &ref->u.ar.where);
+	    return false;
+	  }
 
 	ref->u.ar.as = as;
 	as = NULL;
@@ -5028,6 +5032,8 @@ find_array_spec (gfc_expr *e)
 
   if (as != NULL)
     gfc_internal_error ("find_array_spec(): unused as(2)");
+
+  return true;
 }
 
 
@@ -5346,7 +5352,8 @@ gfc_resolve_ref (gfc_expr *expr)
   for (ref = expr->ref; ref; ref = ref->next)
     if (ref->type == REF_ARRAY && ref->u.ar.as == NULL)
       {
-	find_array_spec (expr);
+	if (!find_array_spec (expr))
+	  return false;
 	break;
       }
 
diff --git a/gcc/testsuite/gfortran.dg/associate_54.f90 b/gcc/testsuite/gfortran.dg/associate_54.f90
index 003175a47fd..680ad5d14a2 100644
--- a/gcc/testsuite/gfortran.dg/associate_54.f90
+++ b/gcc/testsuite/gfortran.dg/associate_54.f90
@@ -26,9 +26,8 @@ contains
     integer, intent(in) :: a
     associate (state => obj%state(TEST_STATES)) ! { dg-error "is used as array" }
 !      state = a
-      state(TEST_STATE) = a
+      state(TEST_STATE) = a ! { dg-error "array reference of a non-array" }
     end associate
   end subroutine test_alter_state1
 
 end module test
-
diff --git a/gcc/testsuite/gfortran.dg/associate_59.f90 b/gcc/testsuite/gfortran.dg/associate_59.f90
new file mode 100644
index 00000000000..2da97731d39
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/associate_59.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/103590 - ICE: find_array_spec(): Missing spec 
+! Contributed by G.Steinmetz
+
+program p
+  associate (a => 1)
+    print *, [character(a(1)) :: '1'] ! { dg-error "Scalar INTEGER expression" }
+  end associate
+end


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-19 21:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 21:28 [gcc r13-1757] Fortran: error recovery on invalid array reference of non-array [PR103590] Harald Anlauf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).