backport: re PR fortran/58058 (Memory leak with transfer function)

2013-08-11  Janus Weil  <janus@gcc.gnu.org>

	Backport from trunk:
	2013-08-09  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/58058
	* trans-intrinsic.c (gfc_conv_intrinsic_transfer): Free the temporary
	string, if necessary.

2013-08-11  Janus Weil  <janus@gcc.gnu.org>

	Backport from trunk:
	2013-08-09  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/58058
	* gfortran.dg/transfer_intrinsic_6.f90: New.

From-SVN: r201653
This commit is contained in:
Janus Weil 2013-08-11 16:08:12 +02:00
parent 73970e0116
commit fb5803b8e3
4 changed files with 45 additions and 2 deletions

View File

@ -1,3 +1,12 @@
2013-08-11 Janus Weil <janus@gcc.gnu.org>
Backport from trunk:
2013-08-09 Janus Weil <janus@gcc.gnu.org>
PR fortran/58058
* trans-intrinsic.c (gfc_conv_intrinsic_transfer): Free the temporary
string, if necessary.
2013-07-08 Tobias Burnus <burnus@net-b.de>
PR fortran/57785

View File

@ -5623,8 +5623,7 @@ scalar_transfer:
if (expr->ts.type == BT_CHARACTER)
{
tree direct;
tree indirect;
tree direct, indirect, free;
ptr = convert (gfc_get_pchar_type (expr->ts.kind), source);
tmpdecl = gfc_create_var (gfc_get_pchar_type (expr->ts.kind),
@ -5657,6 +5656,13 @@ scalar_transfer:
tmp = build3_v (COND_EXPR, tmp, direct, indirect);
gfc_add_expr_to_block (&se->pre, tmp);
/* Free the temporary string, if necessary. */
free = gfc_call_free (tmpdecl);
tmp = fold_build2_loc (input_location, GT_EXPR, boolean_type_node,
dest_word_len, source_bytes);
tmp = build3_v (COND_EXPR, tmp, free, build_empty_stmt (input_location));
gfc_add_expr_to_block (&se->post, tmp);
se->expr = tmpdecl;
se->string_length = fold_convert (gfc_charlen_type_node, dest_word_len);
}

View File

@ -1,3 +1,11 @@
2013-08-11 Janus Weil <janus@gcc.gnu.org>
Backport from trunk:
2013-08-09 Janus Weil <janus@gcc.gnu.org>
PR fortran/58058
* gfortran.dg/transfer_intrinsic_6.f90: New.
2013-07-16 Iain Sandoe <iain@codesourcery.com>
PR target/55656

View File

@ -0,0 +1,20 @@
! { dg-do compile }
! { dg-options "-fdump-tree-original" }
!
! PR 58058: [4.7/4.8/4.9 Regression] Memory leak with transfer function
!
! Contributed by Thomas Jourdan <thomas.jourdan@orange.fr>
implicit none
integer, dimension(3) :: t1
character(len=64) :: str
t1 = (/1,2,3/)
str = transfer(t1,str)
end
! { dg-final { scan-tree-dump-times "__builtin_free" 1 "original" } }
! { dg-final { cleanup-tree-dump "original" } }