Commit 1acbf7a1 by Thomas Koenig

re PR fortran/52861 ((missed optimisation) missed transformation to memset with -O3)

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.

From-SVN: r188305
parent 17c4f786
2012-06-07 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52861
* frontend-passes (empty_string): Add prototype.
* 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
* frontend-passes.c (empty_string): Add prototype.
(optimize_assignment): Set the length of an empty string
constant to zero.
......
......@@ -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;
}
......
2012-06-07 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52861
* gfortran.dg/string_assign_2.f90: New test case.
2012-06-07 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52861
* gfortran.dg/string_assign_1.f90: New test case.
2012-06-07 Jakub Jelinek <jakub@redhat.com>
......
! { 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment