From 993ac38b0fd488754dad42d4202447cabc9d3156 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Fri, 14 Nov 2008 18:03:05 +0000 Subject: [PATCH] re PR fortran/38033 (Bounds of a pointer/allocatable array not stabilized) 2008-10-14 Paul Thomas PR fortran/38033 * trans-array.c (gfc_trans_create_temp_array): Stabilize the 'to' expression. (gfc_conv_loop_setup): Use the end expression for the loop 'to' if it is available. 2008-10-14 Paul Thomas PR fortran/38033 * gfortran.dg/array_section_2.f90: New test. From-SVN: r141861 --- gcc/fortran/ChangeLog | 8 ++++++++ gcc/fortran/trans-array.c | 15 +++++++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/array_section_2.f90 | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/array_section_2.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 2b4fbaa9659..b80aa9e7d4b 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2008-10-14 Paul Thomas + + PR fortran/38033 + * trans-array.c (gfc_trans_create_temp_array): Stabilize the + 'to' expression. + (gfc_conv_loop_setup): Use the end expression for the loop 'to' + if it is available. + 2008-11-12 Jakub Jelinek PR target/35366 diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 218c401af80..9cede5cc84f 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -650,8 +650,10 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post, { /* Callee allocated arrays may not have a known bound yet. */ if (loop->to[n]) - loop->to[n] = fold_build2 (MINUS_EXPR, gfc_array_index_type, - loop->to[n], loop->from[n]); + loop->to[n] = + gfc_evaluate_now (fold_build2 (MINUS_EXPR, + gfc_array_index_type, loop->to[n], + loop->from[n]), pre); loop->from[n] = gfc_index_zero_node; } @@ -3511,8 +3513,13 @@ gfc_conv_loop_setup (gfc_loopinfo * loop, locus * where) break; case GFC_SS_SECTION: - loop->to[n] = gfc_conv_section_upper_bound (loopspec[n], n, - &loop->pre); + /* Use the end expression if it exists and is not constant, + so that it is only evaluated once. */ + if (info->end[n] && !INTEGER_CST_P (info->end[n])) + loop->to[n] = info->end[n]; + else + loop->to[n] = gfc_conv_section_upper_bound (loopspec[n], n, + &loop->pre); break; case GFC_SS_FUNCTION: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fcb30224c36..a239488fa1e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-10-14 Paul Thomas + + PR fortran/38033 + * gfortran.dg/array_section_2.f90: New test. + 2008-11-14 Jakub Jelinek PR tree-optimization/38104 diff --git a/gcc/testsuite/gfortran.dg/array_section_2.f90 b/gcc/testsuite/gfortran.dg/array_section_2.f90 new file mode 100644 index 00000000000..bfb4c01e6af --- /dev/null +++ b/gcc/testsuite/gfortran.dg/array_section_2.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original" } +! +! PR38033 - size(a) was not stabilized correctly and so the expression was +! evaluated twice outside the loop and then within the scalarization loops. +! +! Contributed by Thomas Bruel +! +program test + integer, parameter :: n = 100 + real, pointer :: a(:),temp(:) ! pointer or allocatable have the same effect + allocate(a(n), temp(n)) + temp(1:size(a)) = a +end program +! { dg-final { scan-tree-dump-times "size0" 1 "original" } } +! { dg-final { cleanup-tree-dump "original" } } -- 2.30.2