Bug 44211 - [OOP] ICE with TBP of pointer component of derived type array
Summary: [OOP] ICE with TBP of pointer component of derived type array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: janus
URL:
Keywords: ice-on-valid-code
: 44465 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-05-20 12:18 UTC by Hans-Werner Boschmann
Modified: 2010-06-09 14:16 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.6.0
Last reconfirmed: 2010-06-08 02:32:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hans-Werner Boschmann 2010-05-20 12:18:18 UTC
module ice_module
  type::ice_type
     class(ice_type),pointer::next
   contains
     procedure::ice_proc
  end type ice_type
contains
  subroutine ice_proc(this)
    class(ice_type)::this
  end subroutine ice_proc
  subroutine ice_sub()
    type(ice_type),dimension(2)::ice_array
    class(ice_type),pointer::ice_p
    ice_p=>ice_array(2)%next             ! works
    call ice_array(2)%ice_proc()         ! works
    call ice_array(2)%next%ice_proc()    ! ICE
  end subroutine ice_sub
end module ice_module

Compiling this with GNU Fortran (GCC) 4.6.0 20100518 (experimental) will cause
a segmentation violation at compile time.

The two lines with "! works" and ice_p are not relevant, they only show that the combination of the array, the pointer component and the type bound procedure is really necessary for the compiler error.
Comment 1 janus 2010-05-20 19:01:46 UTC
Confirmed. Backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000571d67 in gfc_conv_scalarized_array_ref (se=0x7fffffffd6a0, ar=0x17f6048) at /home/jweil/gcc46/trunk/gcc/fortran/trans-array.c:2497
2497        n = se->loop->order[0];
(gdb) bt
#0  0x0000000000571d67 in gfc_conv_scalarized_array_ref (se=0x7fffffffd6a0, ar=0x17f6048) at /home/jweil/gcc46/trunk/gcc/fortran/trans-array.c:2497
#1  0x0000000000571f17 in gfc_conv_array_ref (se=0x7fffffffd6a0, ar=0x17f6048, sym=0x17f4370, where=0x17f40f0)
    at /home/jweil/gcc46/trunk/gcc/fortran/trans-array.c:2550
#2  0x00000000005988e0 in gfc_conv_variable (se=0x7fffffffd6a0, expr=0x17f40a0) at /home/jweil/gcc46/trunk/gcc/fortran/trans-expr.c:702
#3  0x00000000005a3712 in gfc_conv_expr (se=0x7fffffffd6a0, expr=0x17f40a0) at /home/jweil/gcc46/trunk/gcc/fortran/trans-expr.c:4453
#4  0x000000000059a833 in get_proc_ptr_comp (e=0x17f2560) at /home/jweil/gcc46/trunk/gcc/fortran/trans-expr.c:1529
#5  0x000000000059a88b in conv_function_val (se=0x7fffffffdd60, sym=0x17effb0, expr=0x17f2560) at /home/jweil/gcc46/trunk/gcc/fortran/trans-expr.c:1541
#6  0x000000000059fe41 in gfc_conv_procedure_call (se=0x7fffffffdd60, sym=0x17effb0, arg=0x0, expr=0x17f2560, append_args=0x0)
    at /home/jweil/gcc46/trunk/gcc/fortran/trans-expr.c:3323
Comment 2 janus 2010-06-08 02:32:38 UTC
Ok, this one took me a while to figure out, but in the end it turns out the fix is actually pretty simple, once you found out where the problem is:


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 160351)
+++ gcc/fortran/resolve.c	(working copy)
@@ -5415,6 +5415,9 @@ resolve_typebound_function (gfc_expr* e)
   if (st == NULL)
     return resolve_compcall (e, NULL);
 
+  if (resolve_ref (e) == FAILURE)
+    return FAILURE;
+
   /* Get the CLASS declared type.  */
   declared = get_declared_from_expr (&class_ref, &new_ref, e);
 
@@ -5487,6 +5490,9 @@ resolve_typebound_subroutine (gfc_code *code)
   if (st == NULL)
     return resolve_typebound_call (code, NULL);
 
+  if (resolve_ref (code->expr1) == FAILURE)
+    return FAILURE;
+
   /* Get the CLASS declared type.  */
   declared = get_declared_from_expr (&class_ref, &new_ref, code->expr1);
 

One can construct a test case analogous to comment #0 using a type-bound function, which would also fail. The patch above fixes both flavors.
Comment 3 janus 2010-06-08 14:22:24 UTC
*** Bug 44465 has been marked as a duplicate of this bug. ***
Comment 4 janus 2010-06-09 14:15:38 UTC
Subject: Bug 44211

Author: janus
Date: Wed Jun  9 14:14:08 2010
New Revision: 160478

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160478
Log:
2010-06-09  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44211
	* resolve.c (resolve_typebound_function,resolve_typebound_subroutine):
	Resolve references.


2010-06-09  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44211
	* gfortran.dg/typebound_call_14.f03: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/typebound_call_14.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 janus 2010-06-09 14:16:58 UTC
Fixed with r160478. Closing.