http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50960
--- Comment #13 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-11-03 14:03:40 UTC --- 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. */