@@ -2238,6 +2238,7 @@ typedef struct
int flag_align_commons;
int flag_whole_file;
int flag_protect_parens;
+ int flag_realloc_lhs;
int fpe;
int rtcheck;
@@ -171,7 +171,7 @@ and warnings}.
-fblas-matmul-limit=@var{n} -frecursive -finit-local-zero @gol
-finit-integer=@var{n} -finit-real=@var{<zero|inf|-inf|nan|snan>} @gol
-finit-logical=@var{<true|false>} -finit-character=@var{n} @gol
--fno-align-commons -fno-protect-parens}
+-fno-align-commons -fno-protect-parens -frealloc_lhs}
@end table
@menu
@@ -1458,6 +1458,13 @@ levels such that the compiler does not do any re-association. Using
@code{COMPLEX} expressions to produce faster code. Note that for the re-association
optimization @option{-fno-signed-zeros} and @option{-fno-trapping-math}
need to be in effect.
+
+@item -frealloc-lhs
+@opindex @code{frealloc_lhs}
+@cindex Reallocate the LHS in assignments
+An allocatable left-hand side of an intrinsic assignment is automatically
+(re)allocated if it is either unallocated or has a different shape. The
+option is enabled by default except when @option{-std=f95} is given.
@end table
@xref{Code Gen Options,,Options for Code Generation Conventions,
@@ -478,6 +478,10 @@ frange-check
Fortran
Enable range checking during compilation
+frealloc_lhs
+Fortran
+Reallocate the LHS in assignments
+
frecord-marker=4
Fortran RejectNegative
Use a 4-byte record marker for unformatted files
@@ -149,6 +149,7 @@ gfc_init_options (unsigned int decoded_options_count,
gfc_option.flag_init_character_value = (char)0;
gfc_option.flag_align_commons = 1;
gfc_option.flag_protect_parens = 1;
+ gfc_option.flag_realloc_lhs = -1;
gfc_option.fpe = 0;
gfc_option.rtcheck = 0;
@@ -266,6 +267,16 @@ gfc_post_options (const char **pfilename)
if (flag_associative_math == -1)
flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
+ /* By default, disable (re)allocation during assignment for -std=f95,
+ and enable it for F2003/F2008/GNU/Legacy. */
+ if (gfc_option.flag_realloc_lhs == -1)
+ {
+ if (gfc_option.allow_std & GFC_STD_F2003)
+ gfc_option.flag_realloc_lhs = 1;
+ else
+ gfc_option.flag_realloc_lhs = 0;
+ }
+
/* -fbounds-check is equivalent to -fcheck=bounds */
if (flag_bounds_check)
gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
@@ -964,6 +975,10 @@ gfc_handle_option (size_t scode, const char *arg, int value,
gfc_option.flag_protect_parens = value;
break;
+ case OPT_frealloc_lhs:
+ gfc_option.flag_realloc_lhs = value;
+ break;
+
case OPT_fcheck_:
gfc_handle_runtime_check_option (arg);
break;
@@ -3230,8 +3230,7 @@ gfc_conv_ss_startstride (gfc_loopinfo * loop)
continue;
/* Catch allocatable lhs in f2003. */
- if (gfc_option.allow_std & GFC_STD_F2003
- && ss->is_alloc_lhs)
+ if (gfc_option.flag_realloc_lhs && ss->is_alloc_lhs)
continue;
gfc_start_block (&inner);