Bug 42335 - [OOP] ICE on CLASS IS (bad_identifier)
[OOP] ICE on CLASS IS (bad_identifier)
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.5.0
: P3 normal
: 4.5.0
Assigned To: janus
: ice-on-invalid-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-12-08 21:46 UTC by Harald Anlauf
Modified: 2009-12-22 17:59 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-12-09 18:17:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Anlauf 2009-12-08 21:46:09 UTC
Hi,

the following (invalid) code gives an ICE:

module gfcbug95
  implicit none
  type, abstract :: vector_class
  end type vector_class

  type, extends(vector_class) :: trivial_vector_type
    real :: elements(100)
  end type trivial_vector_type
contains
  subroutine bar (this,v)
    class(trivial_vector_type), intent(inout) :: this
    class(vector_class),        intent(in)    :: v

    select type (v)
!   class is (trivial_vector_type) ! OK
    class is (bad_id)              ! ICE
       this%elements(:) = v%elements(:)
    end select
  end subroutine bar
end module gfcbug95

% gfc45 gfcbug95.f90
gfcbug95.f90:16.20:

    class is (bad_id)              ! ICE
                    1
Error: 'bad_id' at (1) is not an accessible derived type
f951: internal compiler error: Segmentation fault

Cheers,
-ha
Comment 1 janus 2009-12-09 18:03:20 UTC
> Error: 'bad_id' at (1) is not an accessible derived type
> f951: internal compiler error: Segmentation fault

Confirmed. The same happens for TYPE IS (bad_id).

Comment 2 janus 2009-12-09 18:06:04 UTC
Backtrace:

#0  0x0000000000549274 in gfc_find_sym_tree (name=0x7fffffffd840 "v", ns=0x17a28b0, parent_flag=1, result=0x7fffffffd750)
    at /home/jweil/gcc45/fortran-dev/gcc/fortran/symbol.c:2507
#1  0x000000000054970e in gfc_get_ha_sym_tree (name=0x7fffffffd840 "v", result=0x7fffffffd7d0) at /home/jweil/gcc45/fortran-dev/gcc/fortran/symbol.c:2679
#2  0x0000000000517810 in gfc_match_rvalue (result=0x7fffffffd908) at /home/jweil/gcc45/fortran-dev/gcc/fortran/primary.c:2505
#3  0x00000000004fdadf in match_primary (result=0x7fffffffd908) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:161
#4  0x00000000004fdc5a in match_level_1 (result=0x7fffffffd960) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:234
#5  0x00000000004fdd0a in match_mult_operand (result=0x7fffffffd9c0) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:288
#6  0x00000000004fdf06 in match_add_operand (result=0x7fffffffda08) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:377
#7  0x00000000004fe1b2 in match_level_2 (result=0x7fffffffda60) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:501
#8  0x00000000004fe33c in match_level_3 (result=0x7fffffffdac0) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:572
#9  0x00000000004fe43b in match_level_4 (result=0x7fffffffdb10) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:620
#10 0x00000000004fe6c9 in match_and_operand (result=0x7fffffffdb60) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:714
#11 0x00000000004fe74d in match_or_operand (result=0x7fffffffdbb0) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:743
#12 0x00000000004fe84c in match_equiv_operand (result=0x7fffffffdc00) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:786
#13 0x00000000004fe94b in match_level_5 (result=0x7fffffffdc50) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:832
#14 0x00000000004fea89 in gfc_match_expr (result=0x7fffffffddc8) at /home/jweil/gcc45/fortran-dev/gcc/fortran/matchexp.c:891
#15 0x00000000004f751e in gfc_match (target=0x10f534e " %e%t") at /home/jweil/gcc45/fortran-dev/gcc/fortran/match.c:1102
#16 0x00000000004f7b53 in gfc_match_assignment () at /home/jweil/gcc45/fortran-dev/gcc/fortran/match.c:1300
Comment 3 janus 2009-12-09 18:17:29 UTC
Mine.

I think this one-liner is all that's needed:

Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c        (revision 155023)
+++ gcc/fortran/symbol.c        (working copy)
@@ -2476,7 +2476,7 @@ select_type_insert_tmp (gfc_symtree **st)
 {
   gfc_select_type_stack *stack = select_type_stack;
   for (; stack; stack = stack->prev)
-    if ((*st)->n.sym == stack->selector)
+    if ((*st)->n.sym == stack->selector && stack->tmp)
       *st = stack->tmp;
 }


With this, the test case gives:

c0.f90:16.20:

    class is (bad_id)              ! ICE
                    1
Error: 'bad_id' at (1) is not an accessible derived type
c0.f90:17.36:

       this%elements(:) = v%elements(:)
                                    1
Error: 'elements' at (1) is not a member of the 'vector_class' structure
Comment 4 janus 2009-12-11 14:40:58 UTC
Subject: Bug 42335

Author: janus
Date: Fri Dec 11 14:40:36 2009
New Revision: 155162

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155162
Log:
gcc/fortran/
2009-12-11 Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42335
	* symbol.c (select_type_insert_tmp): Add an extra check for
	error recovery.


gcc/testsuite/
2009-12-11  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42335
	* gfortran.dg/select_type_11.f03: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/select_type_11.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 janus 2009-12-11 15:02:03 UTC
Fixed with r155162. Thanks for the report.