diff mbox

[fortran] Fix PR 48352 - regression with ICE with front end optimization

Message ID 4D94E40A.2060306@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig March 31, 2011, 8:28 p.m. UTC
Hello world,

the attached patch fixes a 4.7 regression, PR 48352, where a function 
elimination in the expressions for a DO loop caused an ICE.  The ICE was 
caused by interaction of the expression walker with insertion of a 
statement for a DO loop.

Many thanks to Joost for finding the bug and reducing the test case.

To fix the regression, I have disabled this particular optimization for 
expressions within the loop control.

I'd like to overhaul the way that statements are inserted during front 
end optimization, later. This is needed for functions returning arrays 
with bounds not known at compile-time anyway.

Regression-tested.  OK for trunk?

	Thomas

2011-03-31  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/48352
         * frontend-passes (cfe_register_funcs):  Don't
         register functions if they appear as iterators in DO loops.

2011-03-31  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/48352
         * gfortran.dg/function_optimize_3.f90:  New test.
! { dg-do compile }
! { dg-options "-O" }
! PR 48352 - variable elimination in a DO loop caused segfaults.
! Test case contributed by Joost VandeVondele
program main
  INTEGER, DIMENSION(:), POINTER :: a
  DO I=1,MIN(SIZE(a),SIZE(a))
  ENDDO
END program main

Comments

Jerry DeLisle April 1, 2011, 12:41 a.m. UTC | #1
On 03/31/2011 01:28 PM, Thomas Koenig wrote:
> Hello world,
>
> the attached patch fixes a 4.7 regression, PR 48352, where a function
> elimination in the expressions for a DO loop caused an ICE. The ICE was caused
> by interaction of the expression walker with insertion of a statement for a DO
> loop.
>
> Many thanks to Joost for finding the bug and reducing the test case.
>
> To fix the regression, I have disabled this particular optimization for
> expressions within the loop control.
>
> I'd like to overhaul the way that statements are inserted during front end
> optimization, later. This is needed for functions returning arrays with bounds
> not known at compile-time anyway.
>
> Regression-tested. OK for trunk?
>
OK.  Do you plan to open a second PR for this TODO?

Thanks for patch,

Jerry
Thomas Koenig April 1, 2011, 7:37 p.m. UTC | #2
Hi Jerry,

>> Regression-tested. OK for trunk?
>>
> OK.  Do you plan to open a second PR for this TODO?

Sending        fortran/ChangeLog
Sending        fortran/frontend-passes.c
Sending        testsuite/ChangeLog
Adding         testsuite/gfortran.dg/function_optimize_3.f90
Transmitting file data ....
Committed revision 171849.

I have opened PR 48405 to track the issue.

Thanks for the review!

	Thomas
diff mbox

Patch

Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 171793)
+++ frontend-passes.c	(Arbeitskopie)
@@ -137,6 +137,13 @@  static int
 cfe_register_funcs (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED,
 	  void *data ATTRIBUTE_UNUSED)
 {
+
+  /* FIXME - there is a bug in the insertion code for DO loops.  Bail
+     out here.  */
+
+  if ((*current_code)->op == EXEC_DO)
+    return 0;
+
   if ((*e)->expr_type != EXPR_FUNCTION)
     return 0;