PR 50892 Latent bug in char pointer assignment
authorJanne Blomqvist <jb@gcc.gnu.org>
Sat, 6 Jan 2018 10:41:03 +0000 (12:41 +0200)
committerJanne Blomqvist <jb@gcc.gnu.org>
Sat, 6 Jan 2018 10:41:03 +0000 (12:41 +0200)
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

gcc/fortran/ChangeLog
gcc/fortran/trans-expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/char_pointer_assign_icb_1.f90 [new file with mode: 0644]

index b001a8a1845a1b792b28550ae7dc639dd1312a0a..59ce3d0d210b0f601cacaca5c8aa003be88fcf37 100644 (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
index 533435ae0c32f29fe3c61a0678a4385a17333794..82fe424396d53979cab37499c2efb9db3e0ff907 100644 (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)));
index 219d0d4865cc08612ec9f452163d1c6c3a7009d7..4c2b209f33a37552bdb71b93ecb166439ab78a46 100644 (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
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 (file)
index 0000000..966757d
--- /dev/null
@@ -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