summaryrefslogtreecommitdiff
path: root/gcc/fortran/frontend-passes.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fortran/frontend-passes.c')
-rw-r--r--gcc/fortran/frontend-passes.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index 4fd24c2947e..bcc1bdc323b 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -740,8 +740,10 @@ optimize_assignment (gfc_code * c)
/* Optimize away a = trim(b), where a is a character variable. */
remove_trim (rhs);
- /* Replace a = ' ' by a = '' to optimize away a memcpy. */
- if (empty_string(rhs))
+ /* Replace a = ' ' by a = '' to optimize away a memcpy, but only
+ for strings with non-deferred length (otherwise we would
+ reallocate the length. */
+ if (empty_string(rhs) && ! lhs->ts.deferred)
rhs->value.character.length = 0;
}