public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul Richard Thomas <paul.richard.thomas@gmail.com>
To: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, fortran] PR70149 - [F08] Character pointer initialization causes ICE
Date: Tue, 25 Sep 2018 16:43:00 -0000	[thread overview]
Message-ID: <CAGkQGiJ8w-bm6TEP47bwf=H2z63joXtQCxnP6UGtqVZQSXMDYA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 559 bytes --]

This is yet another deferred length character bug. The fix speaks for
itself. I'll dream up a more suitable name for the testcase before
committing.

Bootstraps and regtests on FC21/x86_64 - OK for trunk and 8-branch?

Paul

2018-09-25  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/70149
    * trans-decl.c (gfc_get_symbol_decl): A deferred character
    length pointer that is initialized needs the string length to
    be initialized as well.

2018-09-25  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/70149
    * gfortran.dg/pr70149.f90 : New test.

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 757 bytes --]

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 159c3dbb..f7568d5 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1759,7 +1759,17 @@ gfc_get_symbol_decl (gfc_symbol * sym)
       && TREE_CODE (sym->ts.u.cl->backend_decl) != INDIRECT_REF)
     {
       gfc_finish_var_decl (length, sym);
-      gcc_assert (!sym->value);
+      if (!sym->attr.associate_var
+	  && TREE_CODE (length) == VAR_DECL
+	  && sym->value && sym->value->ts.u.cl->length)
+	{
+	  gfc_expr *len = sym->value->ts.u.cl->length;
+	  DECL_INITIAL (length) = gfc_conv_initializer (len, &len->ts,
+							TREE_TYPE (length),
+							false, false, false);
+	}
+      else
+	gcc_assert (!sym->value);
     }
 
   gfc_finish_var_decl (decl, sym);

[-- Attachment #3: pr70149.f90 --]
[-- Type: text/x-fortran, Size: 529 bytes --]

! { dg-do run }
!
! Test the fix for PR70149 in which the string length for
! 'number_string' was not initialized.
!
! Contributed by Walter Spector  <w6ws@earthlink.net>
!
module myptr_mod
  implicit none

  integer, target, save :: int_data = 42
  character(16), target, save :: char_data = 'forty two'

  integer, pointer :: number => int_data
  character(:), pointer :: number_string => char_data

end module

  use myptr_mod
  if (LEN (number_string) .ne. 16) stop 1
  if (trim (number_string) .ne. 'forty two') stop 2
end


             reply	other threads:[~2018-09-25 16:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-25 16:43 Paul Richard Thomas [this message]
2018-09-25 18:36 ` Janne Blomqvist

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGkQGiJ8w-bm6TEP47bwf=H2z63joXtQCxnP6UGtqVZQSXMDYA@mail.gmail.com' \
    --to=paul.richard.thomas@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).