Bug 53653 - [IR Tracking] Disallow abstract/unlimited-polymorphic types in array constructors
Summary: [IR Tracking] Disallow abstract/unlimited-polymorphic types in array construc...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2012-06-13 07:03 UTC by Tobias Burnus
Modified: 2021-06-08 17:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-07-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-06-13 07:03:34 UTC
See thread started at http://j3-fortran.org/pipermail/j3/2012-June/005332.html - and note that there is no IR yet.

Suggested change:
  C4106 (R472) An <ac-value> shall not be unlimited polymorphic or of an
  abstract type.


The following program gives currently an ICE:

test.f90:28:0: internal compiler error: in gfc_conv_array_constructor_expr, at fortran/trans-expr.c:4932
 allocate(y(1), source=[x])
 ^


module m
  abstract interface
    integer function afoo()
    end function
  end interface

  type, abstract :: abstract_base
    integer i
  contains
    procedure(afoo), nopass, deferred :: foo
  end type

  type, extends(abstract_base) :: child
    integer j
  contains
    procedure, nopass :: foo => foo_child
  end type
contains
  integer function foo_child()
    foo_child = 1
  end function
end module

use m
implicit none
class(abstract_base), allocatable :: x, y(:)
allocate(x, source=child(1,2))
allocate(y(1), source=[x])
select type(y)
  type is (child)
    print *, y
  class is (abstract_base)
    print *, y(1)%i
end select
print *, y(1)%foo()
end
Comment 1 Dominique d'Humieres 2014-07-20 08:25:04 UTC
Compiling the code in comment 0 still gives an ICE with gfortran 4.10.0 r212833:

pr53653.f90: In function 'MAIN__':
pr53653.f90:28:0: internal compiler error: in gfc_conv_array_constructor_expr, at fortran/trans-expr.c:5668
 allocate(y(1), source=[x])
 ^

The location of the ICE is the same as for pr51864.
Comment 2 G. Steinmetz 2018-10-22 17:55:51 UTC
Some reductions :


$ cat z1.f90
program p
   type, abstract :: t
   end type
   class(t), allocatable :: x, z(:)
   allocate (z(1), source=[x])
end


$ cat z2.f90
program p
   type t
   end type
   class(t), allocatable :: x, z(:)
   allocate (z(1), source=[x])
end


$ gfortran-9-20181021 -c z2.f90
z2.f90:5:0:

    5 |    allocate (z(1), source=[x])
      |
internal compiler error: Segmentation fault
0xb1c86f crash_signal
        ../../gcc/toplev.c:325
0x5fc806 gfc_add_component_ref(gfc_expr*, char const*)
        ../../gcc/fortran/class.c:211
0x72dbb7 gfc_trans_allocate(gfc_code*)
        ../../gcc/fortran/trans-stmt.c:6048
0x6bdb27 trans_code
        ../../gcc/fortran/trans.c:1990
0x6e51c4 gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6505
0x673426 translate_all_program_units
        ../../gcc/fortran/parse.c:6125
0x673426 gfc_parse_file()
        ../../gcc/fortran/parse.c:6328
0x6ba3ff gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:204
Comment 3 G. Steinmetz 2021-06-08 17:18:56 UTC
Very similar :

$ cat zz1.f90
program p
   type t
   end type
   class(t), allocatable :: a, b(:)
   allocate (b, source=[a])
end


$ gfortran-12-20210606 -c zz1.f90
zz1.f90:5:27:

    5 |    allocate (b, source=[a])
      |                           1
internal compiler error: in gfc_get_element_type, at fortran/trans-types.c:1249
0x81cbea gfc_get_element_type(tree_node*)
        ../../gcc/fortran/trans-types.c:1249
0x7a1f4c gfc_trans_create_temp_array(stmtblock_t*, stmtblock_t*, gfc_ss*, tree_node*, tree_node*, bool, bool, bool, locus*)
        ../../gcc/fortran/trans-array.c:1329
0x7ac382 gfc_conv_loop_setup(gfc_loopinfo*, locus*)
        ../../gcc/fortran/trans-array.c:5319
0x7ac615 gfc_conv_expr_descriptor(gfc_se*, gfc_expr*)
        ../../gcc/fortran/trans-array.c:7555
0x815fff gfc_trans_allocate(gfc_code*)
        ../../gcc/fortran/trans-stmt.c:6289
0x79e617 trans_code
        ../../gcc/fortran/trans.c:2090
0x7c4bc4 gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6893
0x74b3f6 translate_all_program_units
        ../../gcc/fortran/parse.c:6461
0x74b3f6 gfc_parse_file()
        ../../gcc/fortran/parse.c:6730
0x79772f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:212