Bug 58906 - [OOP] SELECT TYPE with CLASS IS generates ICE
Summary: [OOP] SELECT TYPE with CLASS IS generates ICE
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2013-10-28 16:16 UTC by kimwooyoung
Modified: 2014-12-29 11:33 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-10-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kimwooyoung 2013-10-28 16:16:33 UTC
The code fragment causes gfortan to die with a seg fault.
Using 'TYPE IS' instead of 'CLASS IS' seems o.k.

MODULE mymod

  TYPE base
  CONTAINS
  END TYPE base

  TYPE, EXTENDS(base) :: child
    CLASS(*), DIMENSION(:), POINTER :: arr
  CONTAINS
  END TYPE child

CONTAINS

  SUBROUTINE f(r)
    CLASS(base), INTENT(INOUT) ::  r
    SELECT TYPE ( r )
    CLASS IS ( child )
    !TYPE IS ( child )
      SELECT TYPE( iarr=>r%arr )
      TYPE IS ( INTEGER )
        CALL func( iarr )
      END SELECT
    END SELECT
  END SUBROUTINE f

END MODULE mymod

$ gfortran -c reprod2.F90
f951: internal compiler error: Segmentation fault
0x869cbf crash_signal
        ../../gcc-4.8.2/gcc/toplev.c:332
0x56a244 resolve_select_type
        ../../gcc-4.8.2/gcc/fortran/resolve.c:8367
0x56b7cc resolve_code
        ../../gcc-4.8.2/gcc/fortran/resolve.c:10379
0x56d24e resolve_codes
        ../../gcc-4.8.2/gcc/fortran/resolve.c:15047
0x55ddb2 gfc_resolve
        ../../gcc-4.8.2/gcc/fortran/resolve.c:15075
0x56b940 gfc_resolve
        ../../gcc-4.8.2/gcc/fortran/resolve.c:15066
0x56b940 resolve_block_construct
        ../../gcc-4.8.2/gcc/fortran/resolve.c:9367
0x56b940 resolve_code
        ../../gcc-4.8.2/gcc/fortran/resolve.c:10383
0x56a0fb gfc_resolve_blocks(gfc_code*, gfc_namespace*)
        ../../gcc-4.8.2/gcc/fortran/resolve.c:9449
0x56adf3 resolve_code
        ../../gcc-4.8.2/gcc/fortran/resolve.c:10193
0x56a0fb gfc_resolve_blocks(gfc_code*, gfc_namespace*)
        ../../gcc-4.8.2/gcc/fortran/resolve.c:9449
0x56ab1f resolve_select_type
        ../../gcc-4.8.2/gcc/fortran/resolve.c:8681
0x56b7cc resolve_code
        ../../gcc-4.8.2/gcc/fortran/resolve.c:10379
0x56d24e resolve_codes
        ../../gcc-4.8.2/gcc/fortran/resolve.c:15047
0x56d157 resolve_codes
        ../../gcc-4.8.2/gcc/fortran/resolve.c:15033
0x55ddb2 gfc_resolve
        ../../gcc-4.8.2/gcc/fortran/resolve.c:15075
0x552486 gfc_parse_file()
        ../../gcc-4.8.2/gcc/fortran/parse.c:4614
0x58e365 gfc_be_parse_file
        ../../gcc-4.8.2/gcc/fortran/f95-lang.c:189
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Tobias Burnus 2013-10-28 17:24:35 UTC
Confirmed.

ICEs in resolve_select_type for:
      SELECT TYPE( iarr=>r%arr )

where "r%arr" is CLASS(*). Hence,

(gdb) p code->expr2->ts.u.derived->attr.unlimited_polymorphic
$6 = 1
(gdb) p code->expr2->ts.u.derived->ts.u.derived
$7 = (gfc_symbol *) 0x0

but the code does the following (last line derefs a NULL pointer).

7914      if (code->expr2)
7915        {
7916          if (code->expr1->symtree->n.sym->attr.untyped)
7917            code->expr1->symtree->n.sym->ts = code->expr2->ts;
7918          selector_type = CLASS_DATA (code->expr2)->ts.u.derived;
Comment 2 janus 2014-12-29 11:33:39 UTC
Segfaults with 4.8, 4.9 and trunk.

Slightly reduced test case:

  TYPE :: child
    CLASS(*), DIMENSION(:), POINTER :: arr
  END TYPE

CONTAINS

  SUBROUTINE f(r)
    CLASS(child) ::  r
    SELECT TYPE ( r )
    CLASS IS ( child )
      SELECT TYPE( iarr=>r%arr )
      TYPE IS ( INTEGER )
        CALL func( iarr )
      END SELECT
    END SELECT
  END SUBROUTINE

END