This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: (Re)allocation of allocatable arrays on assignment - F2003
Dear Paul,
thanks for the patch.
On 11/04/2010 07:18 AM, Paul Richard Thomas wrote:
In addition to correcting bugs, the main addition to the patch is the
option -f(no-)realloc_lhs. Default behaviour for -std> f95 is to
reallocate on assignment.
I think a '-' instead of a '_' is more in line with most GCC and
gfortran options; essentially only Darwin and SH use some '_' in the
flags. While most of the patch uses realloc_lhs, there is at least one
place where realloc-lhs is used. (As Intel uses "-assume realloc_lhs",
the '_' has also some merits.) Thus, please make the use of '-' vs. '_'
consistent and consider using a hyphen instead of an underscore.
Additionally, the gfortran manpage (as the gcc one) states:
In some cases, options have positive and negative forms; the
negative
form of -ffoo would be -fno-foo. This manual documents only one of
these two forms, whichever one is not the default.
As -std=gnu is the default, which implies -frealloc-lhs/-frealloc_lhs,
we should document
-fno-realloc-lhs/-fno-realloc_lhs instead. Sorry for missing this when I
wrote the patch.
Please note that allocatable assignments of the kind:
x = transformational_array_intrinisic (...)
now produce a temporary unless -fno-realloc_lhs or -std=f95 are
deployed. This could be fixed relatively easily by detecting the
option in the library and repeating the logic of
gfc_alloc_allocatable_for_assignment there.
I think that would be useful - also for cases such as
a = abs(a)
where the RHS is a elemental* function as one knows that the LHS and RHS
must have the same shape. However, such a patch can be deferred.
Bootstrapped and regtested on FC9/x86_64 - OK for trunk?
The patch looks OK.
@@ -3676,6 +3700,11 @@ gfc_conv_loop_setup (gfc_loopinfo * loop, locus *
where)
continue;
}
+ /* Avoid using an allocatable lhs in an assignment, since
+ there might be a reallocation coming. */
+ if (loopspec[n] && ss->is_alloc_lhs)
+ continue;
+
I was wondering whether one should also add a
"gfc_option.flag_realloc_lhs &&" to the if.
+}
+
+/* Allocate the lhs of an assignment to an allocatable array, otherwise
Add another empty line before the comment.
Tobias