Bug 54990 - [4.8 Regression] [OOP] ICE in tree_operand_check on SELECT TYPE
Summary: [4.8 Regression] [OOP] ICE in tree_operand_check on SELECT TYPE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P4 normal
Target Milestone: 4.8.0
Assignee: Paul Thomas
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2012-10-19 17:07 UTC by janus
Modified: 2013-01-07 19:10 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-12-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2012-10-19 17:07:30 UTC
Reported by Andrew Benson at http://gcc.gnu.org/ml/fortran/2012-10/msg00094.html. Reduced test case:


program test
  implicit none
  
  type :: ncBhStd
  end type

  type :: tn
    class (ncBhStd), allocatable, dimension(:) :: cBh
  end type
  
  type(tn), target :: a

  select type (q => a%cBh(1))
  end select

end


Compiles cleanly with 4.7, but trunk gives the following ICE:


internal compiler error: tree check: expected class ‘expression’, have ‘declaration’ (var_decl) in tree_operand_check, at tree.h:4109
 program test
 ^
linux-vdso.so.1: No such file or directory
0xcf07be tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*)
        /home/jweil/gcc48/trunk/gcc/tree.c:8947
0x62d6a8 expr_check
        /home/jweil/gcc48/trunk/gcc/tree.h:3845
0x62d6a8 tree_operand_check
        /home/jweil/gcc48/trunk/gcc/tree.h:4109
0x62d6a8 gfc_get_vptr_from_expr(tree_node*)
        /home/jweil/gcc48/trunk/gcc/fortran/trans-expr.c:199
0x667411 trans_associate_var
        /home/jweil/gcc48/trunk/gcc/fortran/trans-stmt.c:1256
0x66771c gfc_trans_block_construct(gfc_code*)
        /home/jweil/gcc48/trunk/gcc/fortran/trans-stmt.c:1319
0x5fb900 trans_code
        /home/jweil/gcc48/trunk/gcc/fortran/trans.c:1412
0x5fbc62 gfc_trans_code(gfc_code*)
        /home/jweil/gcc48/trunk/gcc/fortran/trans.c:1573
0x62add7 gfc_generate_function_code(gfc_namespace*)
        /home/jweil/gcc48/trunk/gcc/fortran/trans-decl.c:5353
0x5fbca6 gfc_generate_code(gfc_namespace*)
        /home/jweil/gcc48/trunk/gcc/fortran/trans.c:1590
0x59d211 translate_all_program_units
        /home/jweil/gcc48/trunk/gcc/fortran/parse.c:4467
0x59d877 gfc_parse_file()
        /home/jweil/gcc48/trunk/gcc/fortran/parse.c:4681
0x5e8900 gfc_be_parse_file
        /home/jweil/gcc48/trunk/gcc/fortran/f95-lang.c:191
Comment 1 Paul Thomas 2012-12-16 15:27:24 UTC
trans-expr.c:203

tree
gfc_get_vptr_from_expr (tree expr)
{
  tree tmp = expr;
  while (tmp && !GFC_CLASS_TYPE_P (TREE_TYPE (tmp)))
    tmp = TREE_OPERAND (tmp, 0);
  tmp = gfc_class_vptr_get (tmp);
  return tmp;
}

is changed to

tree
gfc_get_vptr_from_expr (tree expr)
{
  tree tmp = expr;
  while (tmp && !GFC_CLASS_TYPE_P (TREE_TYPE (tmp))
	 && !(TYPE_CANONICAL (TREE_TYPE (tmp))
	      && GFC_CLASS_TYPE_P (TYPE_CANONICAL (TREE_TYPE (tmp)))))
    tmp = TREE_OPERAND (tmp, 0);
  tmp = gfc_class_vptr_get (tmp);
  return tmp;
}

the bug is fixed.  The array reference seems to spin a new TREE_TYPE for the class container that does not get marked as GFC_CLASS_TYPE_P.  I have no idea why or what might have changed it.

As soon as I get the unlimited polymorphic patch committed, I will submit this as a patch with the testcase:

program test
  implicit none
  type :: ncBhStd
    integer :: i
  end type
  type :: tn
    class (ncBhStd), allocatable, dimension(:) :: cBh
  end type
  integer :: i
  type(tn), target :: a
  allocate (a%cBh(2), source = [(ncBhStd(i*99), i = 1,2)])
  select type (q => a%cBh(1))
    type is (ncBhStd)
      if (q%i .ne. 99) call abort
  end select

end
Comment 2 Paul Thomas 2013-01-07 09:06:26 UTC
Fixed by http://gcc.gnu.org/viewcvs?view=revision&revision=194953

It did not register here because I screwed up on the ChangeLog Format (I really am rusty  :-) ).  I'll fix this tonight.

Thanks for the report.

Paul
Comment 3 Paul Thomas 2013-01-07 19:10:41 UTC
Author: pault
Date: Mon Jan  7 19:10:32 2013
New Revision: 194994

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194994
Log:
2013-01-07  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/53876
	PR fortran/54990
	PR fortran/54992
	* ChangeLog: Correct format error in revision 194953

2013-01-07  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/53876
	PR fortran/54990
	PR fortran/54992
	* ChangeLog: Correct format error in revision 194953

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/testsuite/ChangeLog