public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "anlauf at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/85547] Run-time error: character array constructor
Date: Wed, 20 Jan 2021 21:01:43 +0000	[thread overview]
Message-ID: <bug-85547-4-4K5vPl4O6y@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-85547-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85547

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #6 from anlauf at gcc dot gnu.org ---
The trim() and string concatenation are not even needed to see the string
length getting lost.

Example:

program p
  implicit none
  character(10) :: path = 'xyz/'
  print *, len      ( [ character(16) :: path ] ) ! ok
  call print_string ( [ character(16) :: path ] ) ! typespec lost
contains
  subroutine print_string (s)
    character(*), intent(in) :: s(:)
    print *, len(s), len(s)==16
  end subroutine
end program

prints:

          16
          10 F

Inspection of the tree-dump shows that the temporary creation for the
subroutine call looks like we initially have the proper string length
after the array constructor

    atmp.6.dtype = {.elem_len=16, .rank=1, .type=6};
    atmp.6.dim[0].stride = 1;
    atmp.6.dim[0].lbound = 0;
    atmp.6.dim[0].ubound = 0;
    atmp.6.span = 16;

which gets copied to the temporary

    atmp.9.dtype = {.elem_len=10, .rank=1, .type=6};
    atmp.9.dim[0].stride = 1;
    atmp.9.dim[0].lbound = 0;
    atmp.9.dim[0].ubound = 0;
    atmp.9.span = 10;

I wonder where we get this from.

Besides, we actually create two temporaries in succession instead of just
one...

       reply	other threads:[~2021-01-20 21:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-85547-4@http.gcc.gnu.org/bugzilla/>
2021-01-20 21:01 ` anlauf at gcc dot gnu.org [this message]
2023-09-06 17:34 ` anlauf at gcc dot gnu.org

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=bug-85547-4-4K5vPl4O6y@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).