]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/71795 (Two Bugs in array constructors (optimization))
authorThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 9 Aug 2016 20:33:00 +0000 (20:33 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 9 Aug 2016 20:33:00 +0000 (20:33 +0000)
2016-08-09  Thomas Koenig  <tkoenig@gcc.gnu.org>

Backport from trunk
PR fortran/71795
* frontend-passes.c (combine_array_constructor):  Don't
do anything if the expression is inside an array iterator.

2016-08-09  Thomas Koenig  <tkoenig@gcc.gnu.org>

Backport from trunk
PR fortran/71795
* gfortran.dg/array_constructor_50.f90:  New test.

From-SVN: r239302

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

index 6881684d12689b45b0896a305048714f6d46f511..f45d0a86fabb7746421e5729d757e4158f5c7274 100644 (file)
@@ -1,3 +1,10 @@
+2016-08-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/71795
+       * frontend-passes.c (combine_array_constructor):  Don't
+       do anything if the expression is inside an array iterator.
+
 2016-08-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        Backport from trunk
index 31d7caf66893926496027a9b3e2fcc7afd089a24..0177dfa1b1c4243e32fefcd5b6cd7452a9ac699e 100644 (file)
@@ -1221,6 +1221,11 @@ combine_array_constructor (gfc_expr *e)
   if (forall_level > 0)
     return false;
 
+  /* Inside an iterator, things can get hairy; we are likely to create
+     an invalid temporary variable.  */
+  if (iterator_level > 0)
+    return false;
+
   op1 = e->value.op.op1;
   op2 = e->value.op.op2;
 
index a7ee12126ac2b4d8de336d42af8f7d5e8d6c6850..b6dcc4ecd44c1069578c4d6cb09a4379286bb325 100644 (file)
@@ -1,3 +1,9 @@
+2016-08-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/71795
+       * gfortran.dg/array_constructor_50.f90:  New test.
+
 2016-08-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/69742
diff --git a/gcc/testsuite/gfortran.dg/array_constructor_50.f90 b/gcc/testsuite/gfortran.dg/array_constructor_50.f90
new file mode 100644 (file)
index 0000000..c22c980
--- /dev/null
@@ -0,0 +1,21 @@
+! { dg-do run }
+! PR 71795 - wrong result when putting an array constructor
+! instide an iterator.
+     program test
+
+     implicit none
+     integer :: i,n
+     logical, dimension(1) :: ra
+     logical :: rs
+     integer, allocatable :: a(:)
+
+     allocate ( a(1) )
+
+     n = 1
+     a = 2
+
+     ra = (/ (any(a(i).eq.(/1,2,3/)) ,i=1,n) /)
+     if (.not. all(ra)) call abort
+     rs = any ( (/ (any(a(i).eq.(/1,2,3/)) ,i=1,n) /) )
+     if (.not. rs) call abort
+   end program test