PR 50892 Latent bug in char pointer assignment

Due to r256284 (PR 78534) there was a latent bug that reared it's head
due to different character length types in the pointer
assignment. Fixed by this patch, which also adds a reduced testcase.

Regtested on x86_64-pc-linux-gnu, committed to trunk as obvious.

gcc/fortran/ChangeLog:

2018-01-06  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/50892
	* trans-expr.c (gfc_trans_pointer_assignment): fold_convert rhs to
	lhs type.

gcc/testsuite/ChangeLog:

2018-01-06  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/50892
	* gfortran.dg/char_pointer_assign_icb_1.f90: New test.

From-SVN: r256310
This commit is contained in:
Janne Blomqvist 2018-01-06 12:41:03 +02:00
parent 59931fb066
commit ee2d398746
4 changed files with 27 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2018-01-06 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/50892
* trans-expr.c (gfc_trans_pointer_assignment): fold_convert rhs to
lhs type.
2018-01-05 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/78534

View File

@ -8392,7 +8392,9 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, gfc_expr * expr2)
if (expr1->ts.deferred)
{
if (expr2->expr_type != EXPR_NULL && lse.string_length != NULL)
gfc_add_modify (&block, lse.string_length, rse.string_length);
gfc_add_modify (&block, lse.string_length,
fold_convert (TREE_TYPE (lse.string_length),
rse.string_length));
else if (lse.string_length != NULL)
gfc_add_modify (&block, lse.string_length,
build_zero_cst (TREE_TYPE (lse.string_length)));

View File

@ -1,3 +1,8 @@
2018-01-06 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/50892
* gfortran.dg/char_pointer_assign_icb_1.f90: New test.
2018-01-06 Jakub Jelinek <jakub@redhat.com>
PR debug/83480

View File

@ -0,0 +1,13 @@
! { dg-do compile }
! Reduced testcase from PR 50892, regressed due to r256284 (PR 78534)
subroutine test
use, intrinsic :: ISO_C_Binding, only: c_ptr
type(c_ptr) :: text
character(len=:), pointer :: ftext
ftext => FortranChar(text)
contains
function FortranChar ( C )
type(c_ptr), intent(in), value :: C
character(len=10), pointer :: FortranChar
end function FortranChar
end subroutine test