Bug 92960 - ICE tree check: expected tree that contains 'decl minimal' structure, have 'component_ref' in add_decl_as_local, at fortran/trans-decl.c:261
Summary: ICE tree check: expected tree that contains 'decl minimal' structure, have 'c...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: associate
  Show dependency treegraph
 
Reported: 2019-12-16 20:04 UTC by G. Steinmetz
Modified: 2023-03-29 08:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-01-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2019-12-16 20:04:12 UTC
Affects versions down to gfortran-8 :


$ cat z1.f90
program p
   type t(n)
      integer, len :: n
      character(n) :: c
   end type
   type(t(:)), allocatable :: z
   allocate (t(7) :: z)
   associate (y => z%c)
      ! print *, y
   end associate
end


$ gfortran-10-20191215 -c z1.f90
z1.f90:8:0:

    8 |    associate (y => z%c)
      |
internal compiler error: tree check: expected tree that contains 'decl minimal' structure, have 'component_ref' in add_decl_as_local, at fortran/trans-decl.c:261
0x5ef00f tree_contains_struct_check_failed(tree_node const*, tree_node_structure_enum, char const*, int, char const*)
        ../../gcc/tree.c:9859
0x73e77d contains_struct_check(tree_node*, tree_node_structure_enum, char const*, int, char const*)
        ../../gcc/tree.h:3387
0x73e77d add_decl_as_local
        ../../gcc/fortran/trans-decl.c:261
0x73e77d gfc_finish_var_decl
        ../../gcc/fortran/trans-decl.c:646
0x73d3de gfc_get_symbol_decl(gfc_symbol*)
        ../../gcc/fortran/trans-decl.c:1829
0x740cbf generate_local_decl
        ../../gcc/fortran/trans-decl.c:5872
0x6f1dc2 do_traverse_symtree
        ../../gcc/fortran/symbol.c:4165
0x7358bf generate_local_vars
        ../../gcc/fortran/trans-decl.c:6078
0x7358bf gfc_process_block_locals(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:7089
0x7a7469 gfc_trans_block_construct(gfc_code*)
        ../../gcc/fortran/trans-stmt.c:2267
0x70b137 trans_code
        ../../gcc/fortran/trans.c:1960
0x7424cd gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6801
0x6bc426 translate_all_program_units
        ../../gcc/fortran/parse.c:6302
0x6bc426 gfc_parse_file()
        ../../gcc/fortran/parse.c:6541
0x70742f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:210
Comment 1 Martin Liška 2020-01-21 14:49:09 UTC
Started with r8-3056-g5bab4c9631c478b7940e952ea57de680321d5a8e. Before that it was rejected:

$ gcc-7 pr92960.f90 -c
pr92960.f90:2:3:

    type t(n)
   1
Error: Unclassifiable statement at (1)
pr92960.f90:3:14:

       integer, len :: n
              1
Error: Invalid character in name at (1)
pr92960.f90:5:6:

    end type
      1
Error: Expecting END PROGRAM statement at (1)
pr92960.f90:6:9:

    type(t(:)), allocatable :: z
         1
Error: Derived type ‘t’ at (1) is being used before it is defined
pr92960.f90:7:13:

    allocate (t(7) :: z)
             1
Error: Allocate-object at (1) is neither a data pointer nor an allocatable variable
pr92960.f90:8:14:

    associate (y => z%c)
              1
Error: Expected association at (1)
pr92960.f90:10:6:

    end associate
      1
Error: Expecting END PROGRAM statement at (1)
pr92960.f90:4:16:

       character(n) :: c
                1
Error: Variable ‘n’ cannot appear in the expression at (1)
pr92960.f90:4:23:

       character(n) :: c
                       1
Error: ‘c’ at (1) must have constant character length in this context
Comment 2 Paul Thomas 2023-03-29 08:45:20 UTC
Fixed on 12-branch and mainline. I will add the testcase below, when the current patch for some of PR87477 is committed.

Thanks

Paul

! { dg-do-run }
!
! Contributed by Gerhard Steinmetz  <gscfq@t-online.de>
!
program p
   type t(n)
      integer, len :: n
      character(n) :: c
   end type
   type(t(:)), allocatable :: z
   allocate (t(7) :: z)
   z%c = "1234567"
   associate (y => z%c)
       if (y .ne. "1234567") stop 1
       if (len (y) .ne. 7) stop 2
   end associate
   deallocate (z)
end