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/109148] New: ICE with explicit-/assumed-size arrays and CLASS
Date: Wed, 15 Mar 2023 19:56:48 +0000	[thread overview]
Message-ID: <bug-109148-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 109148
           Summary: ICE with explicit-/assumed-size arrays and CLASS
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gcc dot gnu.org
  Target Milestone: ---

The following is a spin-off from pr58331.  Consider:

module mymod
  implicit none
  type t
     integer :: i
  end type t
contains
  subroutine mysub(a, n)
    integer,  intent(in) :: n
    class(*), intent(in) :: a(n)

    select type(a)
    type is(integer)
       print *,'a is integer'
       print *, "n=", n, '  a=', a
    class default
       print *,'a is unsupported type'
       stop 1
    end select
  end

  subroutine sub_t(a, n)
    integer,  intent(in) :: n
    class(t), intent(in) :: a(n)

    select type(a)
    class is(t)
       print *,'a is type(t)'
       print *, "n=", n, '  a=', a%i
    class default
       print *,'a is unsupported type'
       stop 1
    end select
  end

  ! Unlimited polymorphic variant
  subroutine sub_star(a, n)
    integer,  intent(in) :: n
    class(*), intent(in) :: a(n)

    select type(a)
    type is(integer)
       print *,'a is integer'
       print *, "n=", n, '  a=', a
    class is(t)
       print *,'a is type(t)'
       print *, "n=", n, '  a=', a%i
    class default
       print *,'a is unsupported type'
       stop 1
    end select
  end
end

program p
  use mymod
  implicit none
  integer :: b(2,2) = reshape([21, 22, 23, 24], [2,2])
  type(t) :: x(2,2) = reshape([t(5), t(6),t(7),t(8)], [2,2])
  type(t) :: y(4)   = [t(15), t(16),t(17),t(18)]
  class(t), allocatable :: w(:)
  class(t), allocatable :: z(:,:)

  allocate (z, source=x)
  allocate (w, source=y)

  call mysub   (b,4) ! see pr58331
! call sub_t   (b,4) ! correctly rejected
  call sub_t   (y,4)
  call sub_t   (z,4) ! OK (although wrong code with crayftn 14.0)
  call sub_t   (w,4) ! OK
  call sub_star(b,4) ! ok
  call sub_star(y,4) ! ok
! call sub_star(x,4) ! ICE in gfc_conv_derived_to_class
! call sub_t   (x,4) ! ICE in gfc_conv_derived_to_class
end

This compiles and seems to work fine with r13-6698.  But uncommenting one
of the last two calls produces:

class_dummy_11.f90:76:54:

   76 |  call sub_star(x,4) ! ICE in gfc_conv_derived_to_class
      |                                                      1
internal compiler error: in gfc_conv_derived_to_class, at
fortran/trans-expr.cc:831
0x70cdc0 gfc_conv_derived_to_class(gfc_se*, gfc_expr*, gfc_typespec,
tree_node*, bool, bool, tree_node**)
        ../../gcc-trunk/gcc/fortran/trans-expr.cc:831
0xa2dcdd gfc_conv_procedure_call(gfc_se*, gfc_symbol*, gfc_actual_arglist*,
gfc_expr*, vec<tree_node*, va_gc, vl_embed>*)
        ../../gcc-trunk/gcc/fortran/trans-expr.cc:6223
0xa81f22 gfc_trans_call(gfc_code*, bool, tree_node*, tree_node*, bool)
        ../../gcc-trunk/gcc/fortran/trans-stmt.cc:424
0x9ee9d3 trans_code
        ../../gcc-trunk/gcc/fortran/trans.cc:2018
0xa20eb1 gfc_generate_function_code(gfc_namespace*)
        ../../gcc-trunk/gcc/fortran/trans-decl.cc:7704
0x99a587 translate_all_program_units
        ../../gcc-trunk/gcc/fortran/parse.cc:6720
0x99a587 gfc_parse_file()
        ../../gcc-trunk/gcc/fortran/parse.cc:7026
0x9eb4df gfc_be_parse_file
        ../../gcc-trunk/gcc/fortran/f95-lang.cc:229


The code seems to work with Nvidia 23.1, works mostly with Crayftn 14.0,
but fails at runtime with Intel 2021.8.

             reply	other threads:[~2023-03-15 19:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 19:56 anlauf at gcc dot gnu.org [this message]
2023-03-16  9:07 ` [Bug fortran/109148] " marxin 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-109148-4@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).