This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, fortran,committed] Fix regression introduced by PR 52861 patch
- From: Thomas Koenig <tkoenig at netcologne dot de>
- To: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 07 Jun 2012 16:35:41 +0200
- Subject: [patch, fortran,committed] Fix regression introduced by PR 52861 patch
Hello world,
my recent patch introduced a regression with deferred-length
characters. I have committed the attached patch as obvious
to fix this.
Regards
Thomas
2012-06-07 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52861
* frontend-passes.c (optimize_assignment): Don't set the
length of an empty string for deferred-length character
variables.
2012-06-07 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52861
* gfortran.dg/string_assign_2.f90: New test case.
Index: frontend-passes.c
===================================================================
--- frontend-passes.c (Revision 188300)
+++ frontend-passes.c (Arbeitskopie)
@@ -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;
}
! { dg-do run }
! { dg-options "-ffrontend-optimize" }
program main
character (len=:), allocatable :: a
a = 'a'
if (len(a) /= 1) call abort
a = ' '
if (len(a) /= 2) call abort
end program main