public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, committed] Fortran: error recovery on invalid array section [PR108609]
@ 2023-02-01 20:24 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2023-02-01 20:24 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 586 bytes --]

Dear all,

the fix for PR108527 came with a testcase that revealed a latent
bug with array sections and invalid array declarations.  The ICE
first popped up on powerpc64-linux-gnu (big endian), but the issue
was not so clear as such on x86_64-pc-linux-gnu, as it did not show
up e.g. in valgrind.  The traceback provided by Bill provided the
right hints, after which the fix became trivial and obvious.

Regtested on x86_64-pc-linux-gnu and confirmed on powerpc64-linux-gnu
by Bill in the PR.  Pushed as:

https://gcc.gnu.org/g:88a2a09dd4529107e7ef7a6e7ce43acf96457173

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr108609.patch --]
[-- Type: text/x-patch, Size: 1109 bytes --]

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 3036b1be60f..c295721b9d6 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -1552,7 +1552,11 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
       lower = ref->u.ar.as->lower[d];
       upper = ref->u.ar.as->upper[d];

-      if (!lower || !upper)
+      if (!lower || !upper
+	  || lower->expr_type != EXPR_CONSTANT
+	  || upper->expr_type != EXPR_CONSTANT
+	  || lower->ts.type != BT_INTEGER
+	  || upper->ts.type != BT_INTEGER)
 	{
 	  t = false;
 	  goto cleanup;
diff --git a/gcc/testsuite/gfortran.dg/pr108527.f90 b/gcc/testsuite/gfortran.dg/pr108527.f90
index c97ba3111cb..804514810ac 100644
--- a/gcc/testsuite/gfortran.dg/pr108527.f90
+++ b/gcc/testsuite/gfortran.dg/pr108527.f90
@@ -4,7 +4,7 @@

 program p
   integer, parameter :: a((2.)) = [4,8] ! { dg-error "must be of INTEGER type" }
-  integer(a(1:1)) :: b                  ! { dg-error "out of bounds" }
+  integer(a(1:1)) :: b                  ! { dg-error "Unclassifiable statement" }
 end

 ! { dg-prune-output "Parameter array" }

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

only message in thread, other threads:[~2023-02-01 20:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-01 20:24 [PATCH, committed] Fortran: error recovery on invalid array section [PR108609] 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).