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/113671] Passing allocatable character(:) slices with negative stride: invalid memory access / segfault
Date: Tue, 30 Jan 2024 19:50:31 +0000	[thread overview]
Message-ID: <bug-113671-4-llQA664v3m@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113671-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from anlauf at gcc dot gnu.org ---
Another reduced variant:

program arrays10
  implicit none
  character(5), allocatable :: a(:)
  character(:), allocatable :: b(:)
  a = [ character(5) :: "one", "two", "three"]
  b = [ character(5) :: "one", "two", "three"]
  call test02 (a) ! OK
  call test02 (b) ! OK
  call test02 (a(size(a):1:-1)) ! OK
  call test02 (b(size(b):1:-1)) ! random junk or crash
contains
  subroutine test02 (a)
    character(*), intent(in) :: a(:)
    print *, a
  end
end

This prints at runtime e.g.

% ./a.out | cat -ev
 one  two  three$
 one  two  three$
 threetwo  one  $
 one  ^@^@^@^@^@^@^@!^@^@$

Forcing an explicit temporary helps, as with

  call test02((b(size(b):1:-1)))

***

The uninitialized warnings Steve mentions corresponds to issues visible
in the tree dump: it appears the the length .b is used before it is set.

      parent reply	other threads:[~2024-01-30 19:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30 16:32 [Bug fortran/113671] New: " orbisvicis+gcc at gmail dot com
2024-01-30 18:48 ` [Bug fortran/113671] " kargl at gcc dot gnu.org
2024-01-30 19:50 ` anlauf at gcc dot gnu.org [this message]

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-113671-4-llQA664v3m@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).