Commit d9183bb7 by Paul Thomas

re PR fortran/34537 (ICE or wrong code for TRANSFER of constant string to character)

2008-01-11  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/34537
	* simplify.c (gfc_simplify_transfer): Return NULL if the size
	of the element is unavailable and only assign character length
	to the result, if 'mold' is constant.

2008-01-11  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/34537
	* gfortran.dg/transfer_simplify_8.f90: New test.

From-SVN: r131470
parent c1e3e2d9
2008-01-11 Paul Thomas <pault@gcc.gnu.org>
PR fortran/34537
* simplify.c (gfc_simplify_transfer): Return NULL if the size
of the element is unavailable and only assign character length
to the result, if 'mold' is constant.
2008-01-10 Paul Thomas <pault@gcc.gnu.org> 2008-01-10 Paul Thomas <pault@gcc.gnu.org>
PR fortran/34396 PR fortran/34396
......
...@@ -4121,11 +4121,17 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size) ...@@ -4121,11 +4121,17 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size)
/* Set result character length, if needed. Note that this needs to be /* Set result character length, if needed. Note that this needs to be
set even for array expressions, in order to pass this information into set even for array expressions, in order to pass this information into
gfc_target_interpret_expr. */ gfc_target_interpret_expr. */
if (result->ts.type == BT_CHARACTER) if (result->ts.type == BT_CHARACTER && gfc_is_constant_expr (mold_element))
result->value.character.length = mold_element->value.character.length; result->value.character.length = mold_element->value.character.length;
/* Set the number of elements in the result, and determine its size. */ /* Set the number of elements in the result, and determine its size. */
result_elt_size = gfc_target_expr_size (mold_element); result_elt_size = gfc_target_expr_size (mold_element);
if (result_elt_size == 0)
{
gfc_free_expr (result);
return NULL;
}
if (mold->expr_type == EXPR_ARRAY || mold->rank || size) if (mold->expr_type == EXPR_ARRAY || mold->rank || size)
{ {
int result_length; int result_length;
......
2008-01-11 Paul Thomas <pault@gcc.gnu.org>
PR fortran/34537
* gfortran.dg/transfer_simplify_8.f90: New test.
2008-01-11 Andreas Krebbel <krebbel1@de.ibm.com> 2008-01-11 Andreas Krebbel <krebbel1@de.ibm.com>
* g++.dg/torture/pr34641.C: Add dg-require-visibility. Define * g++.dg/torture/pr34641.C: Add dg-require-visibility. Define
! { dg-do run }
! { dg-options "-O0" }
! PR fortran/34537
! simplify_transfer used to ICE on divide by zero for cases like this,
! where the mold expression is a non-constant character expression.
!
! Testcase contributed by Tobias Burnus <burnus@gcc.gnu.org >
!
character, pointer :: ptr(:)
character(8) :: a
allocate(ptr(9))
ptr = transfer('Sample#0'//achar(0),ptr) ! Causes ICE
if (any (ptr .ne. ['S','a','m','p','l','e','#','0',achar(0)])) call abort
call test(a)
if (a .ne. 'Sample#2') call abort
contains
subroutine test(a)
character(len=*) :: a
a = transfer('Sample#2',a)
end subroutine test
end
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