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

            Bug ID: 129026
           Summary: ICE with a scalar polymorphic coarray passed to an
                    assumed-rank dummy
           Product: gcc
           Version: 17.0
               URL: https://gcc.sashiko.dev/#/patchset/20261122194107.1003
                    43-1-morin-mikael%40orange.fr?part=3
            Status: UNCONFIRMED
          Keywords: accepts-invalid, ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikael at gcc dot gnu.org
  Target Milestone: ---

This is based on the sashiko review at [1].

Based on the AI comment, here is a testcase demonstrating the ICE behaviour:

! { dg-do compile }
! { dg-additional-options "-fcoarray=single" }
!
! The following program used to cause an ICE because the copy back of the
! array descriptor after the call to `as' was generating a reference to the
! first component of `a', which has none in its declared type.

program prog
  implicit none
  type :: t0
  end type
  type, extends(t0) :: t1
    integer :: c1
  end type
  class(t0), allocatable :: x[:]
  allocate(t1 :: x[*])
  select type(x)
  type is (t1)
    x%c1 = 17
  class default
    error stop 1
  end select
  call as(x)
contains
  subroutine as(a)
    class(t0), allocatable :: a(..)
  end subroutine
end program


With -fcoarray=single, it causes:

   23 |   call as(x)
      |            1
internal compiler error: Segmentation fault
0x29faeaf internal_error(char const*, ...)
        ../../src/gcc/diagnostic-global-context.cc:787
0x1352e0f crash_signal
        ../../src/gcc/toplev.cc:325
0x7fc6667516af ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xc16b83 contains_struct_check(tree_node*, tree_node_structure_enum, char
const*, int, char const*)
        ../../src/gcc/tree.h:4208
0xc16b83 gfc_class_data_get(tree_node*)
        ../../src/gcc/fortran/trans-expr.cc:223
0xc2a30a gfc_conv_class_to_class(gfc_se*, gfc_expr*, gfc_typespec, bool, bool,
bool, bool)
        ../../src/gcc/fortran/trans-expr.cc:1345
0xc219cd gfc_conv_procedure_call(gfc_se*, gfc_symbol*, gfc_actual_arglist*,
gfc_expr*, vec<tree_node*, va_gc, vl_embed>*)
        ../../src/gcc/fortran/trans-expr.cc:7911
0xc8fde1 gfc_trans_call(gfc_code*, bool, tree_node*, tree_node*, bool)
        ../../src/gcc/fortran/trans-stmt.cc:497
0xbd3d86 trans_code
        ../../src/gcc/fortran/trans.cc:2474
0xc11364 gfc_generate_function_code(gfc_namespace*)
        ../../src/gcc/fortran/trans-decl.cc:8509
0xb665be translate_all_program_units
        ../../src/gcc/fortran/parse.cc:7751
0xb665be gfc_parse_file()
        ../../src/gcc/fortran/parse.cc:8081
0xbd05cf gfc_be_parse_file
        ../../src/gcc/fortran/f95-lang.cc:251


This should be rejected because of F2023 (15.5.2.7 Allocatable dummy
variables):
> The corank of the actual argument shall be the same as that of the dummy
> argument.

There is a second reason why this should be rejected, but that is less clear.
F2023 (8.5.8.7 Assumed-rank entity):
> The bounds and shape of an assumed-rank entity with the ALLOCATABLE or POINTER
> attribute are determined as specified in 8.5.8.4. 
F2023 (8.5.8.4 Deferred-shape array):
> C834 An array with the POINTER or ALLOCATABLE attribute shall be declared 
> with 
>      a rank-clause or have an array-spec that is a deferred-shape-spec-list.

The rank-clause is currently unsupported (I have opened PR129021 for it).  But
in any case, C834 clearly forbids ALLOCATABLE and POINTER entities from being
assumed-rank, whereas the 8.5.8.7 statement implicitly suggests that an
assumed-rank entity can be ALLOCATABLE or POINTER.  Or an assumed-rank entity
can be ALLOCATABLE or POINTER only with a rank-clause, but then I don't see the
point of being assumed-rank.


[1]:
https://gcc.sashiko.dev/#/patchset/20261122194107.100343-1-morin-mikael%40orange.fr?part=3

Reply via email to