OSDN Git Service

2014-04-29 Thomas Koenig <tkoenig@gcc.gnu.org>
authortkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 29 Mar 2014 11:51:17 +0000 (11:51 +0000)
committertkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 29 Mar 2014 11:51:17 +0000 (11:51 +0000)
PR fortran/60522
* frontend-passes.c (cfe_code):  Do not walk subtrees
for WHERE.

2014-04-29  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/60522
* gfortran.dg/where_4.f90:  New test case.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@208934 138bc75d-0d04-0410-961f-82ee72b054a4

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

index a56f120..35a1bf3 100644 (file)
@@ -1,3 +1,9 @@
+2014-04-29  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/60522
+       * frontend-passes.c (cfe_code):  Do not walk subtrees
+       for WHERE.
+
 2014-03-20  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/60543
index acfb14d..05ecd20 100644 (file)
@@ -442,12 +442,35 @@ cfe_expr_0 (gfc_expr **e, int *walk_subtrees,
    to insert statements as needed.  */
 
 static int
-cfe_code (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED,
-         void *data ATTRIBUTE_UNUSED)
+cfe_code (gfc_code **c, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
 {
   current_code = c;
   inserted_block = NULL;
   changed_statement = NULL;
+
+  /* Do not do anything inside a WHERE statement; scalar assignments, BLOCKs
+     and allocation on assigment are prohibited inside WHERE, and finally
+     masking an expression would lead to wrong-code when replacing
+
+     WHERE (a>0)
+       b = sum(foo(a) + foo(a))
+     END WHERE
+
+     with
+
+     WHERE (a > 0)
+       tmp = foo(a)
+       b = sum(tmp + tmp)
+     END WHERE
+*/
+
+  if ((*c)->op == EXEC_WHERE)
+    {
+      *walk_subtrees = 0;
+      return 0;
+    }
+  
+
   return 0;
 }
 
index 7e77479..e6f2832 100644 (file)
@@ -1,3 +1,8 @@
+2014-04-29  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/60522
+       * gfortran.dg/where_4.f90:  New test case.
+
 2014-03-20  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/60543
diff --git a/gcc/testsuite/gfortran.dg/where_4.f90 b/gcc/testsuite/gfortran.dg/where_4.f90
new file mode 100644 (file)
index 0000000..1ff2e4c
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! PR 60522 - this used to ICE.
+! Original test case Roger Ferrer Ibanez
+subroutine foo(a, b)
+   implicit none
+   integer, dimension(:), intent(inout) :: a
+   integer, dimension(:), intent(in) :: b
+
+   where (b(:) > 0)
+      where (b(:) > 100)
+         a(lbound(a, 1):ubound(a, 1)) = b(lbound(b, 1):ubound(b, 1)) * b(lbound(b, 1):ubound(b, 1)) - 100
+      elsewhere
+         a(lbound(a, 1):ubound(a, 1)) = b(lbound(b, 1):ubound(b, 1)) * b(lbound(b, 1):ubound(b, 1))
+      end where
+   elsewhere
+      a(lbound(a, 1):ubound(a, 1)) = - b(lbound(b, 1):ubound(b, 1)) * b(lbound(b, 1):ubound(b, 1))
+   end where
+end subroutine foo