Bug 83078

Summary: ICE in gfc_typenode_for_spec, at fortran/trans-types.c:1110
Product: gcc Reporter: G. Steinmetz <gscfq>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal Keywords: ice-on-invalid-code, needs-bisection
Priority: P3    
Version: 8.0   
Target Milestone: 10.4   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102816
Host: Target:
Build: Known to work: 10.3.1, 11.2.1, 12.0
Known to fail: 11.2.0 Last reconfirmed: 2017-11-21 00:00:00

Description G. Steinmetz 2017-11-20 17:21:31 UTC
With an undefined value "n" :

$ cat z1.f90
program p
   implicit none
   type t
      integer :: a(n)
   end type t
   type(t) :: x = t([1, 2])
end


$ gfortran-8-20171119 -c z1.f90
z1.f90:1:0:

 program p

internal compiler error: in gfc_typenode_for_spec, at fortran/trans-types.c:1110
0x7a9ee3 gfc_typenode_for_spec(gfc_typespec*, int)
        ../../gcc/fortran/trans-types.c:1110
0x7aa22a gfc_sym_type(gfc_symbol*)
        ../../gcc/fortran/trans-types.c:2213
0x755974 gfc_get_symbol_decl(gfc_symbol*)
        ../../gcc/fortran/trans-decl.c:1716
0x7589c7 generate_local_decl
        ../../gcc/fortran/trans-decl.c:5525
0x71d9ab do_traverse_symtree
        ../../gcc/fortran/symbol.c:4157
0x759622 generate_local_vars
        ../../gcc/fortran/trans-decl.c:5725
0x759622 gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6372
0x6eb720 translate_all_program_units
        ../../gcc/fortran/parse.c:6091
0x6eb720 gfc_parse_file()
        ../../gcc/fortran/parse.c:6294
0x72ff5f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:204
Comment 1 G. Steinmetz 2017-11-20 17:22:00 UTC
Detected without "implicit none" :


$ cat z2.f90
program p
   type t
      integer :: a(n)
   end type t
   type(t) :: x = t([1, 2])
end


$ gfortran-8-20171119 -c z2.f90
z2.f90:3:19:

       integer :: a(n)
                   1
Error: Variable 'n' at (1) in this context must be constant
z2.f90:3:19:

       integer :: a(n)
                   1
Error: Variable 'n' at (1) in this context must be constant
Comment 2 Dominique d'Humieres 2017-11-21 12:25:36 UTC
Confirmed from 4.8 up to trunk (8.0).
Comment 3 Andrew Pinski 2021-12-26 10:27:13 UTC
The trunk gives:
/app/example.f90:7:20:

    7 |    type(t) :: x = t([1, 2])
      |                    1
Error: Bad array spec of component 'a' referenced in structure constructor at (1)
Comment 4 Andrew Pinski 2021-12-26 10:30:52 UTC
Fixed by the patch which fixed PR 102816. So this means it is fixed for GCC 10.4.0, 11.3.0 and GCC 12.