From 128e09f93d6fa5fc367ad2be059c6dd674ef1049 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Mon, 4 Apr 2011 20:22:21 +0000 Subject: [PATCH] re PR fortran/48412 (CP2K miscompiled due to some Fortran frontend pass) 2011-04-04 Thomas Koenig PR fortran/48412 * frontend-passes (cfe_expr_0): Reverse the order of going through the loops. 2011-04-04 Thomas Koenig PR fortran/48412 * function_optimize_4.f90: New test. From-SVN: r171952 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/frontend-passes.c | 8 ++++---- gcc/testsuite/ChangeLog | 5 +++++ .../gfortran.dg/function_optimize_4.f90 | 20 +++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/function_optimize_4.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f9513dbf650..bea09ffe3e4 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2011-04-04 Thomas Koenig + + PR fortran/48412 + * frontend-passes (cfe_expr_0): Reverse the order of going + through the loops. + 2011-04-04 Tobias Burnus Mikael Morin diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 755bae0645d..c2f6bd5b026 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -295,16 +295,16 @@ cfe_expr_0 (gfc_expr **e, int *walk_subtrees, gfc_expr_walker (e, cfe_register_funcs, NULL); - /* Walk backwards through all the functions to make sure we - catch the leaf functions first. */ - for (i=expr_count-1; i>=1; i--) + /* Walk through all the functions. */ + + for (i=1; iexpr_type == EXPR_VARIABLE) continue; newvar = NULL; - for (j=i-1; j>=0; j--) + for (j=0; j + + PR fortran/48412 + * function_optimize_4.f90: New test. + 2011-04-04 Tobias Burnus PR fortran/18918 diff --git a/gcc/testsuite/gfortran.dg/function_optimize_4.f90 b/gcc/testsuite/gfortran.dg/function_optimize_4.f90 new file mode 100644 index 00000000000..20fc46d3078 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/function_optimize_4.f90 @@ -0,0 +1,20 @@ +! { dg-do run } +! { dg-options "-O" } +! PR 48412 - function elimination got temporary varibles in the wrong order. +! Test case contributed by Joost VandeVondele. + +INTEGER FUNCTION S1(m,ma,lx) +INTEGER :: m,ma,lx + +IF (((m < 0).AND.(MODULO(ABS(ma-lx),2) == 1)).OR.& + ((m > 0).AND.(MODULO(ABS(ma-lx),2) == 0))) THEN + S1=1 +ELSE + S1=0 +ENDIF + +END FUNCTION + +INTEGER :: s1 +IF (S1(1,2,1).NE.0) CALL ABORT() +END -- 2.30.2