From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15322 invoked by alias); 10 Feb 2012 08:40:00 -0000 Received: (qmail 15163 invoked by uid 22791); 10 Feb 2012 08:39:58 -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; Fri, 10 Feb 2012 08:39:45 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/52196] New: Add -Wrealloc-lhs Date: Fri, 10 Feb 2012 08:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: 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: 2012-02/txt/msg01045.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52196 Bug #: 52196 Summary: Add -Wrealloc-lhs Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned@gcc.gnu.org ReportedBy: burnus@gcc.gnu.org CC: pault@gcc.gnu.org While (re)allocation of the LHS with intrinsic assignment is a great feature, for hot loops it can cause in some cases a severe slow down. Analyzing a program to find the places where reallocation happens, can be rather difficult. Thus, it would be useful if the compiler could assist by providing the following warnings: (Suggested wording, should be refined.) -Wrealloc-lhs Warn when the compiler inserts code to for allocation or reallocation of an allocatable array variable of intrinsic type in intrinsic assignments. In hot loops, the Fortran 2003 reallocation feature may reduce the performance. If the array is already allocated with the correct shape, consider using a whole-array array-spec (e.g. "(:,:,:)") for the variable on the left-hand side to prevent the reallocation check. See also -frealloc-lhs. -Wrealloc-lhs-all Warn when the compiler inserts code to for allocation or reallocation of an allocatable variable; this includes scalars and derived types. The reason I suggest two flags: The first one is probably the more useful one: intrinsic variables are typically used in hot loops, for arrays the effect is more severe and in many program - even those which use reallocate on assignment - the array realloc-on-assignment for an intrinsic type is rarely used. Additionally, by adding an array section, which encompasses the whole array, reallocation can be prevented without causing further problems. By contrast, for scalars intrinsic types are typically either not allocatable or - as with deferred-length characters - the reallocation is usually intended and not used in hot loops. Similarly for derived types: Assignments are typically not done in hot loops, otherwise, they are either simple scalars (which shouldn't be allocatables) or not used in hot loops. If they have allocatable components, the reallocation is already heavy. Thus, in many cases, -Wrealloc-lhs will show potential hotspots without too many false positives, while the extra warnings of -Wrealloc-lhs-all might be sometimes helpful but should also contain many false positives.