public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR 50892 Latent bug in char pointer assignment
@ 2018-01-06 10:45 Janne Blomqvist
  0 siblings, 0 replies; only message in thread
From: Janne Blomqvist @ 2018-01-06 10:45 UTC (permalink / raw)
  To: fortran, gcc-patches; +Cc: Janne Blomqvist

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.
---
 gcc/fortran/trans-expr.c                                |  4 +++-
 gcc/testsuite/gfortran.dg/char_pointer_assign_icb_1.f90 | 13 +++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/char_pointer_assign_icb_1.f90

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 533435a..82fe424 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/gfortran.dg/char_pointer_assign_icb_1.f90 b/gcc/testsuite/gfortran.dg/char_pointer_assign_icb_1.f90
new file mode 100644
index 0000000..966757d
--- /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
-- 
2.7.4

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-01-06 10:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-06 10:45 [PATCH] PR 50892 Latent bug in char pointer assignment Janne Blomqvist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).