diff mbox series

[fortran] Simplify constants which come from parameter arrays

Message ID 430f9caf-8f48-33ab-1218-615138b69c56@tkoenig.net
State New
Headers show
Series [fortran] Simplify constants which come from parameter arrays | expand

Commit Message

Thomas König March 25, 2018, 10:46 a.m. UTC
Hello world,

the attached patch potentially saves some space in the object file by
simplifying access to individual elements of a parameter array, which
means that the original parameter may not be needed any more.

Regression-tested. OK for trunk?

Regards

	Thomas

2018-03-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/51260
         * resolve.c (resolve_variable): Simplify cases where access to a
         parameter array results in a single constant.

2018-03-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/51260
         * gfortran.dg/parameter_array_element_3.f90: New test.
diff mbox series

Patch

Index: resolve.c
===================================================================
--- resolve.c	(Revision 258501)
+++ resolve.c	(Arbeitskopie)
@@ -5577,6 +5577,11 @@  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.  */
+  if (e->rank == 0 && sym->as && sym->attr.flavor == FL_PARAMETER)
+    gfc_simplify_expr (e, 1);
+
   return t;
 }