From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1622 invoked by alias); 3 Nov 2011 14:18:12 -0000 Received: (qmail 1611 invoked by uid 22791); 3 Nov 2011 14:18:11 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 03 Nov 2011 14:17:54 +0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/50960] [OOP] vtables not marked as constant Date: Thu, 03 Nov 2011 14:18:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-11/txt/msg00269.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50960 --- Comment #14 from Richard Guenther 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).