This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/52196] New: Add -Wrealloc-lhs
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 10 Feb 2012 08:39:07 +0000
- Subject: [Bug fortran/52196] New: Add -Wrealloc-lhs
- Auto-submitted: auto-generated
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.