+2012-06-07 Thomas König <tkoenig@gcc.gnu.org>
+
+ PR fortran/52861
+ * frontend-passes (empty_string): Add prototype.
+ (optimize_assignment): Set the length of an empty string
+ constant to zero.
+
2012-06-04 Tobias Burnus <burnus@net-b.de>
PR fortran/50619
/* Pass manager for Fortran front end.
- Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
Contributed by Thomas König.
This file is part of GCC.
static bool optimize_trim (gfc_expr *);
static bool optimize_lexical_comparison (gfc_expr *);
static void optimize_minmaxloc (gfc_expr **);
+static bool empty_string (gfc_expr *e);
/* How deep we are inside an argument list. */
lhs = c->expr1;
rhs = c->expr2;
- /* Optimize away a = trim(b), where a is a character variable. */
-
if (lhs->ts.type == BT_CHARACTER)
- remove_trim (rhs);
+ {
+ /* 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))
+ rhs->value.character.length = 0;
+ }
if (lhs->rank > 0 && gfc_check_dependency (lhs, rhs, true) == 0)
optimize_binop_array_assignment (c, &rhs, false);
--- /dev/null
+! { dg-do compile }
+! { dg-options "-ffrontend-optimize -fdump-tree-original" }
+! PR 52861 - optimize this to c = '' so that there is
+! no memcpy in the generated code.
+program main
+ character (len=20) :: c
+ c = ' '
+ print *,c
+end program main
+! { dg-final { scan-tree-dump-times "memcpy" 0 "original" } }
+! { dg-final { cleanup-tree-dump "original" } }