]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/90563 (Out of bounds error when compiling with -Wextra)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 13 Aug 2019 22:25:32 +0000 (22:25 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 13 Aug 2019 22:25:32 +0000 (22:25 +0000)
2013-08-13  Thomas Koenig  <tkoenig@gcc.gnu.org>

Backport from trunk
PR fortran/90563
* frontend-passes.c (insert_index): Suppress errors while
simplifying the resulting expression.

2013-08-13  Thomas Koenig  <tkoenig@gcc.gnu.org>

Backport from trunk
PR fortran/90563
* gfortran.dg/do_subsript_5.f90: New test.

From-SVN: r274405

gcc/fortran/ChangeLog
gcc/fortran/frontend-passes.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/do_subscript_5.f90 [new file with mode: 0644]

index 954e80b260b9b27aa087be0797d29285dc897ac1..9484b9992e533a70753fef0aa552e671dab40d13 100644 (file)
@@ -1,7 +1,14 @@
+2013-08-13  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/90563
+       * frontend-passes.c (insert_index): Suppress errors while
+       simplifying the resulting expression.
+
 2019-08-13  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/88072
-       * misc.c (gfc_typename): Do not point to something that ought not to 
+       * misc.c (gfc_typename): Do not point to something that ought not to
        be pointed at.
 
 2019-08-13  Thomas Koenig  <tkoenig@gcc.gnu.org>
index 75b2d05fc85ee2f4dfc75f19ea4203dd65be5baa..08503ea5d1d65ee918dd675acfcd9e1f8042e4e7 100644 (file)
@@ -2519,7 +2519,12 @@ insert_index (gfc_expr *e, gfc_symbol *sym, mpz_t val, mpz_t ret)
   data.sym = sym;
   mpz_init_set (data.val, val);
   gfc_expr_walker (&n, callback_insert_index, (void *) &data);
+
+  /* Suppress errors here - we could get errors here such as an
+     out of bounds access for arrays, see PR 90563.  */
+  gfc_push_suppress_errors ();
   gfc_simplify_expr (n, 0);
+  gfc_pop_suppress_errors ();
 
   if (n->expr_type == EXPR_CONSTANT)
     {
index 187467d470135c343f0afa44276d78d7540123e2..e8b462ac39734eb2ad2c458732ba3a008a111300 100644 (file)
@@ -1,3 +1,9 @@
+2013-08-13  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/90563
+       * gfortran.dg/do_subsript_5.f90: New test.
+
 2019-08-13  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/88072
diff --git a/gcc/testsuite/gfortran.dg/do_subscript_5.f90 b/gcc/testsuite/gfortran.dg/do_subscript_5.f90
new file mode 100644 (file)
index 0000000..54a4f1b
--- /dev/null
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! { dg-additional-options "-Wdo-subscript" }
+! PR 90563 - this used to be rejected, wrongly
+! Original test case by Tobias Neumann
+program test
+      implicit none
+      integer, parameter :: swap(4) = [2,1,3,4]
+      real :: p(20)
+      integer :: j
+
+      p = 0.0
+
+      ! The following warnings are actually bogus, but we are not yet
+      ! clever enough to suppress them.
+      do j=1,6 ! { dg-warning "out of bounds" }
+          if (j<5) then
+              p(j) = p(swap(j)) ! { dg-warning "out of bounds" }
+          endif
+      enddo
+end program