]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/56872 (Incorrect SUM evaluation, involving implied-do loop, with -ffron...
authorThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 8 Apr 2013 19:36:43 +0000 (19:36 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 8 Apr 2013 19:36:43 +0000 (19:36 +0000)
2013-04-08  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/56782
* frontend-passes.c (callback_reduction):  Dont't do
any simplification if there is only a single element
which has an iterator.

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

PR fortran/56782
* gfortran.dg/array_constructor_44.f90:  New test.

From-SVN: r197610

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

index bf6f7d890d51dd13f29959de621cb46273e831bd..538ce473bc6ef8a268d26c883205913c355e778b 100644 (file)
@@ -1,3 +1,10 @@
+2013-04-08  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/56782
+       * frontend-passes.c (callback_reduction):  Dont't do
+       any simplification if there is only a single element
+       which has an iterator.
+
 2013-04-07  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/56849
index a77afc58e4b962f2a5e3101b0b1bcc04cff81975..b2d01169e3bdf3405238b47733fc7552b0ab66b6 100644 (file)
@@ -300,7 +300,12 @@ callback_reduction (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED,
 
   c = gfc_constructor_first (arg->value.constructor);
 
-  if (c == NULL)
+  /* Don't do any simplififcation if we have
+     - no element in the constructor or
+     - only have a single element in the array which contains an
+     iterator.  */
+
+  if (c == NULL || (c->iterator != NULL && gfc_constructor_next (c) == NULL))
     return 0;
 
   res = copy_walk_reduction_arg (c->expr, fn);
index 9fdbdfc0ba18201c6d616efe4c2ee0645418889e..73935171e31993b944f6ebe5c6dec34a075f431c 100644 (file)
@@ -1,3 +1,8 @@
+2013-04-08  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/56782
+       * gfortran.dg/array_constructor_44.f90:  New test.
+
 2013-04-08  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/56871
diff --git a/gcc/testsuite/gfortran.dg/array_constructor_44.f90 b/gcc/testsuite/gfortran.dg/array_constructor_44.f90
new file mode 100644 (file)
index 0000000..e0cffd1
--- /dev/null
@@ -0,0 +1,12 @@
+! { dg-do run }
+! { dg-options "-ffrontend-optimize" }
+! PR 56872 - wrong front-end optimization with a single constructor.
+! Original bug report by Rich Townsend.
+  integer :: k
+  real :: s
+  integer :: m
+  s = 2.0
+  m = 4
+  res = SUM([(s**(REAL(k-1)/REAL(m-1)),k=1,m)])
+  if (abs(res - 5.84732246) > 1e-6) call abort
+  end