Bug 12696 - [3.3 regression] memory eating infinite loop in diagnostics
[3.3 regression] memory eating infinite loop in diagnostics
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c++
3.4.0
: P3 normal
: 3.3.3
Assigned To: Mark Mitchell
: diagnostic
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2003-10-20 21:02 UTC by Christopher Saunders
Modified: 2003-12-18 03:23 UTC (History)
2 users (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build: i386-redhat-linux
Known to work:
Known to fail:
Last reconfirmed: 2003-12-05 03:59:40


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Saunders 2003-10-20 21:02:39 UTC
g++ 3.3.2/3.4 correctly report the error in the example code below, but they
enter an infinite loop until physical memory is exausted. This problem does not
occur with g++ 3.2.2. 

Details:

loop.cc:
"""
struct A {
  static float b[10];
}


float A::b[] = {1,2,3};
"""

0) this is on an i386 (athlon) with a stock redhat 9.0 linux install

1) for g++ 3.2.2, a normal error is reported:
$ /usr/bin/g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

$ /usr/bin/g++ -c loop.cc
loop.cc:6: semicolon missing after declaration of `A'
loop.cc:6: two or more data types in declaration of `b'
loop.cc:6: conflicting types for `A A::b[]'
loop.cc:2: previous declaration as `float A::b[10]'
loop.cc:6: non-empty initializer for array of empty elements
$


2) for g++ 3.3.2, an infinite loop occurs:

$ /opt/gcc-3.3.2/bin/g++ -v
Reading specs from /opt/gcc-3.3.2/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/specs
Configured with: ../gcc-3.3.2/configure --enable-languages=c,c++,f77
-enable-concept-checks --prefix=/opt/gcc-3.3.2
Thread model: posix
gcc version 3.3.2

$ /opt/gcc-3.3.2/bin/g++ -c loop.cc
loop.cc:6: error: semicolon missing after declaration of `A'
loop.cc:6: error: two or more data types in declaration of `b'
loop.cc:6: error: conflicting types for `A A::b[]'
loop.cc:2: error: previous declaration as `float A::b[10]'
loop.cc:6: error: initializer for `A' must be brace-enclosed
loop.cc:6: error: initializer for `A' must be brace-enclosed
loop.cc:6: error: initializer for `A' must be brace-enclosed
.
.
etc...


3) for a recent gcc 3.4 snapshot, the same infinite loop occurs:

$ /opt/gcc-3.4/bin/g++ -v
Reading specs from /opt/gcc-3.4/lib/gcc/i686-pc-linux-gnu/3.4/specs
Configured with: ../gcc-3.4-20031015/configure --enable-languages=c,c++,f77
--prefix=/opt/gcc-3.4 --disable-checking
Thread model: posix
gcc version 3.4 20031015 (experimental)

$ /opt/gcc-3.4/bin/g++ -c loop.cc
loop.cc:6: error: two or more data types in declaration of `b'
loop.cc:6: error: conflicting declaration 'A A::b[]'
loop.cc:2: error: 'A::b' has a previous declaration as `float A::b[10]'
loop.cc:6: error: initializer for `A' must be brace-enclosed
loop.cc:6: error: initializer for `A' must be brace-enclosed
loop.cc:6: error: initializer for `A' must be brace-enclosed
.
.
etc...


4) note that when you s/A::b[]/A::b[N]/ loop.cc, then the error is only reported
N times and the compiler exits normally.
Comment 1 Wolfgang Bangerth 2003-10-20 23:54:48 UTC
Confirmed. With some luck, the loop ends after about 4 billion iterations,
but who wants to wait that long? :-)

Gaby, this looks diagnostics related, so I assign it to you.

W.
Comment 2 Gabriel Dos Reis 2003-10-21 07:11:50 UTC
Subject: Re:  [3.3/3.4 regression] memory eating infinite loop in diagnostics

"bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| Confirmed. With some luck, the loop ends after about 4 billion iterations,
| but who wants to wait that long? :-)
| 
| Gaby, this looks diagnostics related, so I assign it to you.

Thanks!

-- Gaby
Comment 3 Steven Bosscher 2003-12-11 07:57:10 UTC
This seems to be fixed.  I'm not sure since I never saw this bug in the first 
place... 
 
t.c:1: error: missing terminating " character 
t.c:1: error: expected unqualified-id 
t.c:1: error: expected `,' or `;' 
 
Comment 4 CVS Commits 2003-12-17 04:46:00 UTC
Subject: Bug 12696

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2003-12-17 04:45:53

Modified files:
	gcc            : ChangeLog varasm.c 
	gcc/cp         : ChangeLog decl.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/init: error1.C pm3.C 

Log message:
	PR c++/12218
	* varasm.c (initializer_constant_valid_p): Allow a conversion from
	an integral constant to an OFFSET_TYPE.
	
	PR c++/12696
	* decl.c (reshape_init): Recover quickly from errors.
	
	PR c++/12218
	* g++.dg/init/pm3.C: New test.
	
	PR c++/12696
	* g++.dg/init/error1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.2014&r2=2.2015
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&r1=1.399&r2=1.400
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3814&r2=1.3815
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1162&r2=1.1163
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3273&r2=1.3274
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/error1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/pm3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 Mark Mitchell 2003-12-17 05:30:06 UTC
Fixed in GCC 3.4.
Comment 6 Giovanni Bajo 2003-12-17 12:14:50 UTC
Mark, this is a 3.3 regression too. Can the decl.c hunks be backported to the 
branch as well?
Comment 7 Giovanni Bajo 2003-12-18 03:23:29 UTC
Reopening as 3.3 regression only.
Comment 8 CVS Commits 2003-12-26 04:06:50 UTC
Subject: Bug 12696

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	gdr@gcc.gnu.org	2003-12-26 04:06:46

Modified files:
	gcc/cp         : ChangeLog decl.c 
Added files:
	gcc/testsuite/g++.dg/init: error1.C 

Log message:
	Backport from mainline:
	2003-12-16  Mark Mitchell  <mark@codesourcery.com>
	
	PR c++/12696
	* decl.c (reshape_init): Recover quickly from errors.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/error1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.4.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.228&r2=1.3076.2.229
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.965.2.65&r2=1.965.2.66