Bug 54134 - [OOP] ICE overriding derived type bound function with allocatable character as result
[OOP] ICE overriding derived type bound function with allocatable character a...
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.8.0
: P3 normal
: ---
Assigned To: janus
: ice-on-valid-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-31 07:33 UTC by koen.poppe
Modified: 2012-07-31 13:10 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-07-31 00:00:00


Attachments
Code that reproduces the ICE with the correct output from two other compilers. (3.03 KB, application/octet-stream)
2012-07-31 07:33 UTC, koen.poppe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description koen.poppe 2012-07-31 07:33:11 UTC
Created attachment 27903 [details]
Code that reproduces the ICE with the correct output from two other compilers.

Consider the derived type A with no-pass type bound function which has an allocatable character string as result. Now extend this type A with a type B which overrides that function. The combination of this overriding and the fact that the result is allocatable results in an ICE. Removing the inheritance from A and/or changing the result type to a fixed length character string does not trigger the ICE as shown in the attached example.
Comment 1 Tobias Burnus 2012-07-31 09:34:17 UTC
Backtrace:

#0  0x00000000005efd8b in gfc_dep_compare_expr (e1=0x0, e2=0x0) at dependency.c:255
#1  0x0000000000586988 in gfc_check_typebound_override (proc=0x1620ef0, old=0x16237b0) at interface.c:3895
#2  0x00000000005c4c00 in resolve_typebound_procedure (stree=0x1620ef0) at resolve.c:11683
Comment 2 janus 2012-07-31 10:13:29 UTC
Patch:

Index: gcc/fortran/dependency.c
===================================================================
--- gcc/fortran/dependency.c	(revision 189984)
+++ gcc/fortran/dependency.c	(working copy)
@@ -261,6 +261,9 @@ gfc_dep_compare_expr (gfc_expr *e1, gfc_expr *e2)
   n1 = NULL;
   n2 = NULL;
 
+  if (e1 == NULL && e2 == NULL)
+    return 0;
+
   /* Remove any integer conversion functions to larger types.  */
   if (e1->expr_type == EXPR_FUNCTION && e1->value.function.isym
       && e1->value.function.isym->id == GFC_ISYM_CONVERSION


With this, the test case compiles without error and produces the expected result. Will commit as obvious after regtesting.
Comment 3 janus 2012-07-31 13:04:00 UTC
Author: janus
Date: Tue Jul 31 13:03:53 2012
New Revision: 190010

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

	PR fortran/54134
	* dependency.c (gfc_dep_compare_expr): Check if arguments are NULL.

2012-07-31  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54134
	* gfortran.dg/typebound_override_3.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/typebound_override_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/dependency.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 janus 2012-07-31 13:05:40 UTC
Fixed on trunk with r190010. Closing.

Thanks for the report!
Comment 5 koen.poppe 2012-07-31 13:10:46 UTC
Thank you for the quick response and solution!