From: Janne Blomqvist Date: Sat, 6 Jan 2018 10:41:03 +0000 (+0200) Subject: PR 50892 Latent bug in char pointer assignment X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ee2d3987461ecc6ab82d484aeed066597c146587;p=gcc.git 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 PR fortran/50892 * trans-expr.c (gfc_trans_pointer_assignment): fold_convert rhs to lhs type. gcc/testsuite/ChangeLog: 2018-01-06 Janne Blomqvist PR fortran/50892 * gfortran.dg/char_pointer_assign_icb_1.f90: New test. From-SVN: r256310 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b001a8a1845..59ce3d0d210 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-01-06 Janne Blomqvist + + PR fortran/50892 + * trans-expr.c (gfc_trans_pointer_assignment): fold_convert rhs to + lhs type. + 2018-01-05 Janne Blomqvist PR fortran/78534 diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 533435ae0c3..82fe424396d 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -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))); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 219d0d4865c..4c2b209f33a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-06 Janne Blomqvist + + PR fortran/50892 + * gfortran.dg/char_pointer_assign_icb_1.f90: New test. + 2018-01-06 Jakub Jelinek PR debug/83480 diff --git a/gcc/testsuite/gfortran.dg/char_pointer_assign_icb_1.f90 b/gcc/testsuite/gfortran.dg/char_pointer_assign_icb_1.f90 new file mode 100644 index 00000000000..966757d21fb --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_pointer_assign_icb_1.f90 @@ -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