From 06e8d82eba434c70d409b3d61b37b3427733e904 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Mon, 9 Apr 2018 21:05:13 +0000 Subject: [PATCH] re PR fortran/51260 (PARAMETER array with constructor initializer: Compile-time simplify single element access) 2018-04-09 Thomas Koenig PR fortran/51260 * resolve.c (resolve_variable): Simplify cases where access to a parameter array results in a single constant. 2018-04-09 Thomas Koenig PR fortran/51260 * gfortran.dg/parameter_array_element_3.f90: New test. From-SVN: r259256 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/resolve.c | 10 ++++++++++ gcc/testsuite/ChangeLog | 5 +++++ .../gfortran.dg/parameter_array_element_3.f90 | 17 +++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/parameter_array_element_3.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 1d90f4fa317..324fbf3f0bb 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-04-09 Thomas Koenig + + PR fortran/51260 + * resolve.c (resolve_variable): Simplify cases where access to a + parameter array results in a single constant. + 2018-04-02 Thomas Koenig PR fortran/85102 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index e28146a8bf4..18da9476a3c 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -5577,6 +5577,16 @@ resolve_procedure: if (t && flag_coarray == GFC_FCOARRAY_LIB && gfc_is_coindexed (e)) add_caf_get_intrinsic (e); + /* Simplify cases where access to a parameter array results in a + single constant. Suppress errors since those will have been + issued before, as warnings. */ + if (e->rank == 0 && sym->as && sym->attr.flavor == FL_PARAMETER) + { + gfc_push_suppress_errors (); + gfc_simplify_expr (e, 1); + gfc_pop_suppress_errors (); + } + return t; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 21914dff504..d2fefd33de6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-04-09 Thomas Koenig + + PR fortran/51260 + * gfortran.dg/parameter_array_element_3.f90: New test. + 2018-04-09 Jakub Jelinek PR c++/85194 diff --git a/gcc/testsuite/gfortran.dg/parameter_array_element_3.f90 b/gcc/testsuite/gfortran.dg/parameter_array_element_3.f90 new file mode 100644 index 00000000000..ecab68a14b4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/parameter_array_element_3.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! PR 51260 - an unneeded parameter found its way into the +! assembly code. Original test case by Tobias Burnus. +module x +contains + subroutine foo(i) + integer, intent(in) :: i + end subroutine foo +end module x + +program main + use x + integer, parameter:: unneeded_parameter (10000)=(/(i,i=1,10000)/) + call foo(unneeded_parameter (1)) + print *,unneeded_parameter (1) +end program +! { dg-final { scan-assembler-times "unneeded_parameter" 0 } } -- 2.30.2