Bug 38252 - [4.4 Regression] Empty function with CONTAINS triggers Internal Error
Summary: [4.4 Regression] Empty function with CONTAINS triggers Internal Error
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P4 normal
Target Milestone: 4.4.0
Assignee: Mikael Morin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-24 17:59 UTC by Daniel Kraft
Modified: 2008-12-02 14:30 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-11-27 15:40:17


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Kraft 2008-11-24 17:59:05 UTC
This program gives an "Internal Error" pointing at the CONTAINS:

INTEGER FUNCTION test ()
CONTAINS
END FUNCTION test

It works with gfortran 4.3.1.  Replacing the FUNCTION by a SUBROUTINE gets rid of the error.  Additionally, this program also works:

FUNCTION test ()
  INTEGER :: test
CONTAINS
END FUNCTION test
Comment 1 Mikael Morin 2008-11-24 22:52:46 UTC
confirm

quickfix:
Index: parse.c
===================================================================
--- parse.c	(révision 142172)
+++ parse.c	(copie de travail)
@@ -2323,7 +2323,7 @@ parse_spec (gfc_statement st)
       gfc_symbol* proc = gfc_current_ns->proc_name;
       gcc_assert (proc);
 
-      if (proc->result->ts.type == BT_UNKNOWN)
+      if (proc->result->ts.type != BT_UNKNOWN)
 	function_result_typed = true;
     }
 
@@ -2333,7 +2333,7 @@ loop:
      (and thus we can expect to see none any further), type the function result
      if it has not yet been typed.  Be careful not to give the END statement
      to verify_st_order!  */
-  if (!function_result_typed && st != ST_GET_FCN_CHARACTERISTICS)
+  if (!function_result_typed && st == ST_GET_FCN_CHARACTERISTICS)
     {
       bool verify_now = false;
 

I'm probably missing something
Comment 2 Mikael Morin 2008-11-24 23:12:35 UTC
(In reply to comment #1)
> I'm probably missing something
> 
Indeed I was. :'(
FAIL: gfortran.dg/actual_array_result_1.f90
Comment 3 Paul Thomas 2008-11-26 17:22:17 UTC
(In reply to comment #2)

I am on my travels right now and only have 4.4.0 20080624 on my laptop.  The testcase works fine with that, so this regression has crept in since then.

Cheers

Paul
Comment 4 Mikael Morin 2008-11-26 18:02:45 UTC
(In reply to comment #3)
> (In reply to comment #2)
> 
> I am on my travels right now and only have 4.4.0 20080624 on my laptop.  The
> testcase works fine with that, so this regression has crept in since then.

...or it is some changes on my tree I forgot to cleanup.

Did you manage to apply the patch without this?
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139425

I will investigate more next week-end (unless someone beats me ;-)) 
Comment 5 Mikael Morin 2008-11-27 15:40:17 UTC
(In reply to comment #4)
> I will investigate more next week-end (unless someone beats me ;-)) 
> 
I'm investigating now.
The first patch was probably wrong. 
I'm testing this one at the moment:
Index: parse.c
===================================================================
--- parse.c	(r�vision 142242)
+++ parse.c	(copie de travail)
@@ -1576,7 +1576,7 @@ typedef struct
 {
   enum
   { ORDER_START, ORDER_USE, ORDER_IMPORT, ORDER_IMPLICIT_NONE,
-    ORDER_IMPLICIT, ORDER_SPEC, ORDER_EXEC
+    ORDER_IMPLICIT, ORDER_SPEC, ORDER_EXEC, ORDER_CONTAINS
   }
   state;
   gfc_statement last_statement;
@@ -1658,6 +1658,10 @@ verify_st_order (st_state *p, gfc_statement st, bo
 	p->state = ORDER_EXEC;
       break;
 
+    case ST_CONTAINS:
+      p->state = ORDER_CONTAINS;
+      break;
+
     default:
       gfc_internal_error ("Unexpected %s statement in verify_st_order() at %C",
 			  gfc_ascii_statement (st));
Comment 6 Mikael Morin 2008-12-01 19:32:18 UTC
Subject: Bug 38252

Author: mikael
Date: Mon Dec  1 19:30:55 2008
New Revision: 142327

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142327
Log:
2008-12-01  Mikael Morin  <mikael.morin@tele2.fr>

	PR fortran/38252
	* parse.c (parse_spec): Skip statement order check in case
	of a CONTAINS statement.

2008-12-01  Mikael Morin  <mikael.morin@tele2.fr>

	PR fortran/38252
	* gfortran.dg/empty_function_1.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/empty_function_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/parse.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Mikael Morin 2008-12-01 19:52:47 UTC
I hope one day I'll be able to commit properly.
Comment 8 Mikael Morin 2008-12-01 19:53:37 UTC
Subject: Bug 38252

Author: mikael
Date: Mon Dec  1 19:52:15 2008
New Revision: 142331

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142331
Log:
2008-12-01  Mikael Morin  <mikael.morin@tele2.fr>

	PR fortran/38252
	* gfortran.dg/empty_function_1.f90: Fix latest commit.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/empty_function_1.f90

Comment 9 Mikael Morin 2008-12-02 14:30:31 UTC
Fixed on trunk.
Let's not forget to close.