Bug 54778 - [OOP] an ICE on invalid OO code
Summary: [OOP] an ICE on invalid OO code
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2012-10-02 09:50 UTC by Sylwester Arabas
Modified: 2012-10-02 21:52 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-10-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sylwester Arabas 2012-10-02 09:50:08 UTC
Hi, 

Enclosing below the steps to reproduce an ICE on an invalid OO code.

HTH,
Sylwester



$ cat bug.f95 
module bug_m
  implicit none

  type :: arr_t
    real, dimension(:,:), pointer :: at
  end type

  type :: bug_t
    class(arr_t), allocatable :: elements(:)
  end type

  contains

  function elem(this, i)
    type(bug_t), intent(in) :: this
    integer, intent(in) :: i
    class(arr_t) :: elem
    elem = this%elements(i)
  end function
end module

$ /usr/lib/gcc-snapshot/bin/gfortran bug.f95 
bug.f95:14.2:

  function elem(this, i)
  1
Error: CLASS variable 'elem' at (1) must be dummy, allocatable or pointer
f951: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-snapshot/README.Bugs> for instructions.

$ /usr/lib/gcc-snapshot/bin/gfortran --version
GNU Fortran (Debian 20120930-1) 4.8.0 20120930 (experimental) [trunk revision 191865]
Copyright (C) 2012 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
Comment 1 janus 2012-10-02 16:12:50 UTC
Thanks for reporting. I can reproduce this on 4.7 and trunk.


Here is a patch to fix it:

Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c	(revision 191869)
+++ gcc/fortran/interface.c	(working copy)
@@ -3386,7 +3386,8 @@ matching_typebound_op (gfc_expr** tb_base,
 
 	if (base->expr->ts.type == BT_CLASS)
 	  {
-	    if (CLASS_DATA (base->expr) == NULL)
+	    if (CLASS_DATA (base->expr) == NULL
+		|| !gfc_expr_attr (base->expr).class_ok)
 	      continue;
 	    derived = CLASS_DATA (base->expr)->ts.u.derived;
 	  }


With this I get:

c0.f90:14.2:

  function elem(this, i)
  1
Error: CLASS variable 'elem' at (1) must be dummy, allocatable or pointer
c0.f90:18.4:

    elem = this%elements(i)
    1
Error: Variable must not be polymorphic in intrinsic assignment at (1) - check that there is a matching specific subroutine for '=' operator


Regtesting now ...
Comment 2 janus 2012-10-02 19:00:34 UTC
(In reply to comment #1)
> Regtesting now ...

Finished successfully. Will commit as obvious.
Comment 3 janus 2012-10-02 19:31:40 UTC
Btw, here is a slightly simpler version of the test case with the same symptoms:


implicit none

type :: arr_t
  real :: at
end type

type(arr_t) :: this
class(arr_t) :: elem

elem = this

end
Comment 4 janus 2012-10-02 21:02:20 UTC
Author: janus
Date: Tue Oct  2 21:02:16 2012
New Revision: 192005

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192005
Log:
2012-10-02  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54778
	* interface.c (matching_typebound_op): Check for 'class_ok' attribute.

2012-10-02  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54778
	* gfortran.dg/class_53.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/class_53.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 janus 2012-10-02 21:07:43 UTC
Fixed with r192005. Closing.

Thanks again for the report!