Bug 38665 - [4.3 Regression] ICE in check_host_association
Summary: [4.3 Regression] ICE in check_host_association
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P4 normal
Target Milestone: 4.3.3
Assignee: Paul Thomas
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2008-12-29 21:13 UTC by Thomas Koenig
Modified: 2009-01-10 21:44 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.2 4.4.0
Known to fail: 4.3.3
Last reconfirmed: 2009-01-03 23:01:37


Attachments
failing test case (1.91 KB, text/plain)
2008-12-29 21:15 UTC, Thomas Koenig
Details
reduced testcase (275 bytes, text/plain)
2008-12-29 22:07 UTC, Daniel Franke
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2008-12-29 21:13:30 UTC
Error found by Marco Restelli (test case to be uploaded shortly).

gfortran 4.4 fails with

$ gfortran host_assoc.f90
host_assoc.f90:85: internal compiler error: in check_host_association, at fortran/resolve.c:4369
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

gfortran 4.3.2 works.
Comment 1 Thomas Koenig 2008-12-29 21:15:04 UTC
Created attachment 17004 [details]
failing test case
Comment 2 Daniel Franke 2008-12-29 22:07:30 UTC
Created attachment 17006 [details]
reduced testcase
Comment 3 Mikael Morin 2008-12-29 23:13:57 UTC
failing assert line 4338:
 4334           gfc_match_rvalue (&expr);
 4335           gfc_clear_error ();
 4336           gfc_buffer_error (0);
 4337 
 4338           gcc_assert (expr && sym == expr->symtree->n.sym);
 4339 
 4340           *e = *expr;
 4341           gfc_free (expr);
 4342           sym->refs++;

sym->name = "mult"
expr->expr_type = EXPR_VARIABLE
expr->symtree->name = "p1"

if we change the gfc_match_rvalue to a gfc_match_expr, we get a segfault at the same place because expr->symtree = NULL, and even if we remove the gcc_assert, we report an error because the function call has been changed into a multiplication of non-intrinsic types.

Now the solutions:
 (1) Add some conditions to the if before to prevent executing this.
 (2) Remove the gfc_match_whatever that has nothing to do in resolve.c and find a better way (yes, I prefer (2), how did you guess?). 

Hum, maybe (1) is better for 4.4.0 
Comment 4 Jakub Jelinek 2008-12-29 23:22:26 UTC
This is a Fortran FE bug and as such it is P4/P5.  That doesn't mean
it shouldn't be fixed for 4.4, just that it isn't release critical.
Comment 5 Paul Thomas 2009-01-03 23:01:36 UTC
Mikael,
 
> Now the solutions:
>  (1) Add some conditions to the if before to prevent executing this.
>  (2) Remove the gfc_match_whatever that has nothing to do in resolve.c and find
> a better way (yes, I prefer (2), how did you guess?). 
> 
> Hum, maybe (1) is better for 4.4.0 

Believe me, I looked for a better solution when I wrote this function!  It is possible but seems to require more scans of the code tree than I liked - maybe this can be streamlined by marking candidate expressions....

In the mean time, I know how to apply a fix along the lines of 1.

Cheers

Paul 

Comment 6 Mikael Morin 2009-01-04 01:02:49 UTC
(In reply to comment #5)
> Mikael,
> 
> > Now the solutions:
> >  (1) Add some conditions to the if before to prevent executing this.
> >  (2) Remove the gfc_match_whatever that has nothing to do in resolve.c and find
> > a better way (yes, I prefer (2), how did you guess?). 
> > 
> > Hum, maybe (1) is better for 4.4.0 
> 
> Believe me, I looked for a better solution when I wrote this function!  
Well, I didn't think much about it. It's probably the easiest, but I don't like those hacks which are likely to pop up again later. Anyway, I can't blame you for finding a fix for a bug.
> 
> In the mean time, I know how to apply a fix along the lines of 1.
Ok, then; go for (1). I have nothing to propose. 
Comment 7 Paul Thomas 2009-01-04 17:59:15 UTC
(In reply to comment #6)

> > In the mean time, I know how to apply a fix along the lines of 1.
> Ok, then; go for (1). I have nothing to propose. 

I have just realised that the matching can be eliminated, although I would be reluctant to do it in 4.4.  In the case of function replacing function, the actual arglist can be copied over.  Where a host associated variable is masquerading as a contained function, the reference list has to be converted via a helper function into the actual argument list.  This latter will need a bit of thought.  In either case, resolve_function should be called.

I'll add a TODO.
Paul

Comment 8 Paul Thomas 2009-01-04 23:17:48 UTC
Subject: Bug 38665

Author: pault
Date: Sun Jan  4 23:17:37 2009
New Revision: 143064

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

	PR fortran/38665
	* gfortran.h : Add bit to gfc_expr 'user_operator'
	* interface.c (gfc_extend_expr): Set the above if the operator
	is substituted by a function. 
	* resolve.c (check_host_association): Return if above is set.

2009-01-05  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/38665
	* gfortran.dg/host_assoc_function_5.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/host_assoc_function_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 9 Paul Thomas 2009-01-10 21:01:33 UTC
Subject: Bug 38665

Author: pault
Date: Sat Jan 10 21:01:14 2009
New Revision: 143248

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

	PR fortran/38665
	* gfortran.h : Add bit to gfc_expr 'user_operator'
	* interface.c (gfc_extend_expr): Set the above if the operator
	is substituted by a function. 
	* resolve.c (check_host_association): Return if above is set.

2009-01-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/38665
	* gfortran.dg/host_assoc_function_5.f90: New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/host_assoc_function_5.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/gfortran.h
    branches/gcc-4_3-branch/gcc/fortran/interface.c
    branches/gcc-4_3-branch/gcc/fortran/resolve.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 10 Paul Thomas 2009-01-10 21:25:05 UTC
Subject: Bug 38665

Author: pault
Date: Sat Jan 10 21:24:54 2009
New Revision: 143250

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

	PR fortran/38665
	* gfortran.dg/host_assoc_function_5.f90: Clean up extraneous.

Modified:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/host_assoc_function_5.f90

Comment 11 Paul Thomas 2009-01-10 21:41:26 UTC
Subject: Bug 38665

Author: pault
Date: Sat Jan 10 21:41:16 2009
New Revision: 143252

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

	PR fortran/38665
	* gfortran.dg/host_assoc_function_5.f90: Clean up extraneous.

Modified:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/host_assoc_function_5.f90

Comment 12 Paul Thomas 2009-01-10 21:44:36 UTC
Fixed on trunk and latest 4.3

Paul
Comment 13 Paul Thomas 2009-01-10 21:44:59 UTC
Fixed on trunk and latest 4.3

Paul