]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: error recovery on invalid array section [PR108609]
authorHarald Anlauf <anlauf@gmx.de>
Wed, 1 Feb 2023 20:01:32 +0000 (21:01 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 11 Feb 2023 13:56:16 +0000 (14:56 +0100)
The testcase for PR108527 uncovered a latent issue with invalid array
sections that resulted in different paths being taken on different
architectures.  Detect the invalid array declaration for a clean recovery.

gcc/fortran/ChangeLog:

PR fortran/108609
* expr.c (find_array_section): Add check to prevent interpreting an
mpz non-integer constant as an integer.

gcc/testsuite/ChangeLog:

PR fortran/108609
* gfortran.dg/pr108527.f90: Adjust test pattern.

(cherry picked from commit 88a2a09dd4529107e7ef7a6e7ce43acf96457173)

gcc/fortran/expr.c
gcc/testsuite/gfortran.dg/pr108527.f90

index b65fc764fb8dc789ad6e2b1290dac2c2fc479bd0..5f22270c2f099dc05e93a826d3c7fa12cd8b2faa 100644 (file)
@@ -1549,7 +1549,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;
index c97ba3111cbff1cf5affe889402d94eba4df7d1c..804514810acd4dd761919ee4a15447188789bbde 100644 (file)
@@ -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" }