Bug 18596 - [4.0 regression] ICE in make_decl_rtl
Summary: [4.0 regression] ICE in make_decl_rtl
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.0
: P2 minor
Target Milestone: 4.0.0
Assignee: James A. Morrison
URL:
Keywords: error-recovery, ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2004-11-21 15:10 UTC by Andrew Pinski
Modified: 2004-12-21 17:09 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-11-30 20:45:07


Attachments
Robustify c-decl.c (688 bytes, patch)
2004-11-26 06:10 UTC, James A. Morrison
Details | Diff
3rd round of a patch (687 bytes, patch)
2004-11-30 21:40 UTC, James A. Morrison
Details | Diff
Round 4 patch (909 bytes, patch)
2004-12-04 17:24 UTC, James A. Morrison
Details | Diff
Test case 1 (197 bytes, text/plain)
2004-12-04 17:25 UTC, James A. Morrison
Details
test case two (189 bytes, text/plain)
2004-12-04 17:26 UTC, James A. Morrison
Details
test case 3 (197 bytes, text/plain)
2004-12-04 17:26 UTC, James A. Morrison
Details
round 5 or so (897 bytes, patch)
2004-12-17 03:54 UTC, James A. Morrison
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2004-11-21 15:10:29 UTC
With the testcase in 12322, we get an ICE after errors because of nested functions.
Reduced testcase:
int f(int i)
{
  static int g();
  static int g() { return i; }
  return g();
}

: Search converges between 2004-07-27-trunk (#496) and 2004-07-28-trunk (#497).
Comment 1 Giovanni Bajo 2004-11-22 00:51:13 UTC
Confirmed:

18596.c: In function 'f':
18596.c:3: error: invalid storage class for function 'g'
18596.c:4: error: invalid storage class for function 'g'
Comment 2 James A. Morrison 2004-11-26 06:10:29 UTC
Created attachment 7612 [details]
Robustify c-decl.c

 This patch fixes the problem with the testcase.  Unfortunatly, it causes two
more
error messages, i.e.

nested.c:4: error: redefinition of ‘g’
nested.c:3: error: previous definition of ‘g’ was here

 I'm going to regtest this patch then submit it.
Comment 3 Andrew Pinski 2004-11-26 15:47:35 UTC
(In reply to comment #2)
> Created an attachment (id=7612)
> Robustify c-decl.c
> 
>  This patch fixes the problem with the testcase.  Unfortunatly, it causes two
> more
> error messages, i.e.
Maybe the easy way to fix it is not to set the DECL_INITIAL to error_mark_node if it not set yet.
Does that fix the extra error message?
Comment 4 Andrew Pinski 2004-11-27 02:16:38 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-11/msg02350.html>.
Comment 5 GCC Commits 2004-11-30 00:32:41 UTC
Subject: Bug 18596

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	phython@gcc.gnu.org	2004-11-30 00:32:34

Modified files:
	gcc            : c-decl.c ChangeLog 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: pr18596-1.c 

Log message:
	2004-11-26  James A. Morrison  <phython@gcc.gnu.org>
	
	PR middle-end/18596
	* c-decl.c (grokdeclarator): Reset DECL_INTIAL to error_mark_node
	on errors.
	
	testsuite:
	* gcc.dg/pr18596-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.611&r2=1.612
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6634&r2=2.6635
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4687&r2=1.4688
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr18596-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 James A. Morrison 2004-11-30 00:40:59 UTC
Fixed the the previous commit.
Comment 7 Hans-Peter Nilsson 2004-11-30 20:01:08 UTC
I'm reopening this bug, because with LAST_UPDATED "Tue Nov 30 11:22:00 UTC 2004"
(with a local patch to work around the mklibgcc.in breakage at that time, later
fixed) I get the same error this PR is supposed to have fixed:
/gcc/testsuite/gcc.dg/pr18596-1.c: In function 'f':
/gcc/testsuite/gcc.dg/pr18596-1.c:4: error: invalid storage class for function
'g'
/gcc/testsuite/gcc.dg/pr18596-1.c:5: error: ISO C forbids nested functions
/gcc/testsuite/gcc.dg/pr18596-1.c:5: error: invalid storage class for function
'g'
/gcc/testsuite/gcc.dg/pr18596-1.c: In function 'g':
/gcc/testsuite/gcc.dg/pr18596-1.c:5: internal compiler error: in make_decl_rtl,
at varasm.c:867

Note also that the test-case needs a dg-options "" to avoid the automatically
added -ansi.  (How was the test-case tested?)
Comment 8 Hans-Peter Nilsson 2004-11-30 20:02:31 UTC
... on mmix-knuth-mmixware, I forgot to say.
Comment 9 Andrew Pinski 2004-11-30 20:12:37 UTC
Note even without -pedantic we get an ICE still.
Comment 10 James A. Morrison 2004-11-30 20:45:07 UTC
 I probably should be shot for this one.  I'm looking into it.
Comment 11 James A. Morrison 2004-11-30 21:40:56 UTC
Created attachment 7645 [details]
3rd round of a patch

 I'm going to go through a couple rounds of testing this time.
Comment 12 Ben Elliston 2004-12-01 05:05:45 UTC
This patch still causes a regression:

FAIL: gcc.dg/funcdef-storage-1.c (test for excess errors)
Comment 13 James A. Morrison 2004-12-01 05:34:53 UTC
 Strange that it didn't fail on sparc or sparc64 linux.
Comment 14 James A. Morrison 2004-12-01 05:38:06 UTC
 Sorry, did you mean static.nested3.patch ?
Comment 15 James A. Morrison 2004-12-01 07:03:01 UTC
Andrew's patch for 17807 stops funcdef-storage.c from ICEing, but it causes an
extra error in that testcase because it thinks foo should be a nested function.
Comment 16 Andrew Pinski 2004-12-01 12:42:14 UTC
Maybe unsetting the DECL's context will fix the ICE, I don't know for sure.
Comment 17 James A. Morrison 2004-12-04 17:24:33 UTC
Created attachment 7673 [details]
Round 4 patch
Comment 18 James A. Morrison 2004-12-04 17:25:40 UTC
Created attachment 7674 [details]
Test case 1
Comment 19 James A. Morrison 2004-12-04 17:26:02 UTC
Created attachment 7675 [details]
test case two
Comment 20 James A. Morrison 2004-12-04 17:26:23 UTC
Created attachment 7676 [details]
test case 3
Comment 21 James A. Morrison 2004-12-08 05:49:43 UTC
 The round 4 patch causes lots of regressions.
Comment 22 Andrew Pinski 2004-12-10 03:59:00 UTC
Removing patch keyword as the non of the current patches work.
Comment 23 Steven Bosscher 2004-12-10 11:09:38 UTC
Ehm, maybe this is a stupid question - but why are we generating a DECL_RTL
to begin with, given that we have errors?
Comment 24 James A. Morrison 2004-12-10 14:23:03 UTC
 The problem occurs in no-unit-at-a-time mode, so the nested functions are
expanded, and that is where the problems start.
Comment 25 James A. Morrison 2004-12-17 03:54:59 UTC
Created attachment 7767 [details]
round 5 or so

 This patch passes regression testing if the function definition in
funcdef-storage-1.c is removed.
Comment 26 Andrew Pinski 2004-12-19 19:59:15 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01411.html>.
Comment 27 GCC Commits 2004-12-21 17:01:32 UTC
Subject: Bug 18596

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	phython@gcc.gnu.org	2004-12-21 17:01:08

Modified files:
	gcc            : ChangeLog c-decl.c c-parse.in c-typeck.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg: funcdef-storage-1.c pr18596-1.c 
Added files:
	gcc/testsuite/gcc.dg: pr18596-2.c pr18596-3.c 

Log message:
	2004-12-19  James A. Morrison  <phython@gcc.gnu.org>
	
	PR c/18596
	* c-parse.in (initdcl): Don't process a declaration if start_decl fails.
	(notype_initdcl):  Don't process a declaration if start_decl fails.
	* c-decl.c (start_decl): Fail if grokdeclarator fails.
	(grokdeclarator): Fail if a function definition has an invalid storage
	class.
	* c-typeck.c (start_init): Treat error_mark_node the same as 0.
	
	testsuite:
	PR c/18596
	* gcc.dg/funcdef-storage-1.c (foo): Remove.
	* gcc.dg/pr18596-1.c: Use dg-error.
	(dg-options): Use -fno-unit-at-a-time.
	* gcc.dg/pr18596-2.c: New test.
	* gcc.dg/pr18596-3.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6910&r2=2.6911
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.617&r2=1.618
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-parse.in.diff?cvsroot=gcc&r1=1.255&r2=1.256
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.404&r2=1.405
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4788&r2=1.4789
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr18596-2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr18596-3.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/funcdef-storage-1.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr18596-1.c.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 28 James A. Morrison 2004-12-21 17:09:32 UTC
 Lets see if I did it right this time.