Patchwork [Fortran] Fix PR 60522

login
register
mail settings
Submitter Thomas Koenig
Date March 25, 2014, 7:58 a.m.
Message ID <5331372B.4080004@netcologne.de>
Download mbox | patch
Permalink /patch/333306/
State New
Headers show

Comments

Thomas Koenig - March 25, 2014, 7:58 a.m.
Hello world,

the attached patch fixes the regression (after some thought
of what might still be optimized, which isn't much :-)

Regression-tested.  OK for trunk?

	Thomas


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

        PR fortran/60522
        * frontend-passes.c (cfe_code):  Do not walk subtrees
        for WHERE.

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

        PR fortran/60522
        * gfortran.dg/where_4.f90:  New test case.
Tobias Burnus - March 26, 2014, 7:21 a.m.
Thomas Koenig wrote:
> Hello world,

print *, 'Hello Thomas'

> the attached patch fixes the regression (after some thought
> of what might still be optimized, which isn't much :-)
>
> Regression-tested.  OK for trunk?

Looks good to me. (I wonder whether one should also include Mikael's 
test case, but I am not sure whether it is worth a run-time test.)

Thanks for the patch!

Tobias

> 2014-04-25  Thomas Koenig  <tkoenig@gcc.gnu.org>
>
>          PR fortran/60522
>          * frontend-passes.c (cfe_code):  Do not walk subtrees
>          for WHERE.
>
> 2014-04-25  Thomas Koenig  <tkoenig@gcc.gnu.org>
>
>          PR fortran/60522
>          * gfortran.dg/where_4.f90:  New test case.

Patch

Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 208592)
+++ frontend-passes.c	(Arbeitskopie)
@@ -627,12 +627,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;
 }