http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50960

--- Comment #14 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-11-03 
14:17:52 UTC ---
(In reply to comment #13)
> Patch for the issue of comment 5: Constants (PARAMETER) which are exists as
> global static variables were not marked as TREE_READONLY.
> 
> With the patch below (not regtested), the function call is optimized away in:
> 
> module m
>   integer, parameter :: PARA(*) = [1,2,3,4,5,6,7,8,9,10]
> end module m
> 
> subroutine test()
> use m
> integer :: i
> i = 1
> if (para(i) /= 1) call I_am_optimized_away()
> end
> 
> 
> --- a/gcc/fortran/trans-decl.c
> +++ b/gcc/fortran/trans-decl.c
> @@ -517,6 +517,9 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
>    /* If it wasn't used we wouldn't be getting it.  */
>    TREE_USED (decl) = 1;
> 
> +  if (sym->attr.flavor == FL_PARAMETER)
> +    TREE_READONLY (decl) = 1;
> +
>    /* Chain this decl to the pending declarations.  Don't do pushdecl()
>       because this would add them to the current scope rather than the
>       function scope.  */

Yes, that should work iff Fortran does not allow parameter initializers
that require runtime init (like / foo() /, thus a function call result).

Reply via email to