public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/88486] ICE in gfc_conv_scalarized_array_ref, at fortran/trans-array.c:3401
Date: Sun, 28 May 2023 18:52:02 +0000	[thread overview]
Message-ID: <bug-88486-4-oC6VhuPyEV@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-88486-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from kargl at gcc dot gnu.org ---
(In reply to G. Steinmetz from comment #0)
> Affects versions down to at least gfortran-5.
> Under the hood related to pr85686.
> 
> 
> $ cat z1.f90
> subroutine s(x)
>    character(:), allocatable :: x(:)
>    x = ['bcd']
>    x = ['a'//x//'e']
>    print *, x
> end
> 

This compiles with GNU Fortran (GCC) 13.0.1 20230408 (experimental).
This has an ICE with GNU Fortran (FreeBSD Ports Collection) 12.2.0.

Filling out the code to something that actually does something
reveals a wrong-code issue with an array constructor.  There are
a boat load of warnings of uninitialized variables, e.g., 
a.f90:53:34:

   53 |          x = [ ('a' // x // 'e') ]
      |                                  ^
Warning: '__var_1_realloc_string.dim[0].ubound' is used uninitialized
[-Wuninitialized]
a.f90:1:11:

    1 | program foo
      |           ^
note: '__var_1_realloc_string' declared here
a.f90:3:36:

    3 |    character(:), allocatable :: a(:)
      |                                    ^
Warning: '.a' is used uninitialized [-Wuninitialized]
a.f90:34:22:

   34 |       end subroutine s
      |                      ^
note: '.a' declared here


program foo

   character(:), allocatable :: a(:)

   call s(a)
   print '(A,1X,2(I0,1X),/)', 'a: >>' // a // '<<', size(a), len(a(1))
   if (allocated(a)) deallocate(a)

   call t(a)
   print '(A,1X,2(I0,1X),/)', 'a: >>' // a // '<<', size(a), len(a(1))
   if (allocated(a)) deallocate(a)

   call u(a)
   print '(A,1X,2(I0,1X),/)', 'a: >>' // a // '<<', size(a), len(a(1))
   if (allocated(a)) deallocate(a)

   call v(a)
   print '(A,1X,2(I0,1X),/)', 'a: >>' // a // '<<', size(a), len(a(1))
   if (allocated(a)) deallocate(a)

   call w(a)
   print '(A,1X,2(I0,1X),/)', 'a: >>' // a // '<<', size(a), len(a(1))
   if (allocated(a)) deallocate(a)

   contains

      subroutine s(x)
         character(:), allocatable :: x(:)
         x = ['bcd']
         x = ['a' // x // 'e']
         print '(A,1X,2(I0,1X))', 's: >>' // x // '<<', size(x), len(x(1))
      end subroutine s

      subroutine t(x)
         character(:), allocatable :: x(:)
         x = ['bcd']
         x = 'a' // x // 'e'
         print '(A,1X,2(I0,1X))', 't: >>' // x // '<<', size(x), len(x(1))
      end subroutine t

      subroutine u(x)
         character(:), allocatable :: x(:)
         x = ['bcd']
         x = [ ('a' // x // 'e') ]
         print '(A,1X,2(I0,1X))', 'u: >>' // x // '<<', size(x), len(x(1))
      end subroutine u

      subroutine v(x)
         character(:), allocatable, intent(out) :: x(:)
         x = ['bcd']
         x = [ ('a' // x // 'e') ]
         print '(A,1X,2(I0,1X))', 'v: >>' // x // '<<', size(x), len(x(1))
      end subroutine v

      subroutine w(x)
         character(:), allocatable, intent(out) :: x(:)
         x = [ 'a' // ['bcd'] // 'e' ]
         print '(A,1X,2(I0,1X))', 'w: >>' // x // '<<', size(x), len(x(1))
      end subroutine w

end program foo


s: >>abcde<< 1 5
a: >>abc<< 1 3    <--- whoops

t: >>abcde<< 1 5
a: >>abcde<< 1 5

u: >>abcde<< 1 5
a: >>abc<< 1 3    <--- whoops

v: >>abcde<< 1 5
a: >>abc<< 1 3    <--- whoops

w: >>abcde<< 1 5
a: >>abcde<< 1 5

      parent reply	other threads:[~2023-05-28 18:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-88486-4@http.gcc.gnu.org/bugzilla/>
2021-08-28 19:14 ` anlauf at gcc dot gnu.org
2023-05-28 18:20 ` kargl at gcc dot gnu.org
2023-05-28 18:52 ` kargl 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-88486-4-oC6VhuPyEV@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).