Bug 11852 - [3.3/3.4 Regression] ICE: g++ with bad struct initializer.
Summary: [3.3/3.4 Regression] ICE: g++ with bad struct initializer.
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2.2
: P1 critical
Target Milestone: 3.3.2
Assignee: Not yet assigned to anyone
Keywords: ice-on-valid-code
Depends on:
Reported: 2003-08-08 09:42 UTC by Kristian Hogsberg
Modified: 2004-01-17 04:22 UTC (History)
1 user (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Known to work:
Known to fail:
Last reconfirmed: 2003-08-08 12:08:09


Note You need to log in before you can comment on or make changes to this bug.
Description Kristian Hogsberg 2003-08-08 09:42:39 UTC
g++ crashes with an ICE on the following program:

  struct bug {
    const char *name;
    unsigned long type;

  struct bug s = { 0, (unsigned long) &s | 1 };

When compiled as C code, gcc says "initializer element is not computable at load

Output of gcc -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)
Comment 1 Andrew Pinski 2003-08-08 12:08:08 UTC
It did not crash on 2.95.3 (and was accepted).  I can confirm this in 3.3.1 (20030707) and the 
mainline (20030807).
Even 2.97 20001231 crash (according to Phil's regression hunter) and 2.96 (20000731 RedHat) 
Comment 2 Falk Hueffner 2003-08-08 14:37:53 UTC
This is really ice-on-invalid-code, since a constant expression may contain
addresses only with constant offsets. I can't reproduce the ICE with mainline
20030802 on alphaev68-unknown-linux-gnu.
Comment 3 Andrew Pinski 2003-08-08 15:51:57 UTC
Actually it is valid as in C++ you can have initializers which are not constant.  I also can confirm 
this on powerpc-apple-darwin6.6 on the mainline (20030806).
Comment 4 CVS Commits 2003-09-07 23:48:36 UTC
Subject: Bug 11852

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2003-09-07 23:48:34

Modified files:
	gcc            : varasm.c ChangeLog 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/init: struct1.C 

Log message:
	PR c++/11852
	* varasm.c (initializer_constant_valid_p): Correct logic for
	PR c++/11852
	* g++.dg/init/struct1.C: New test.


Comment 6 Mark Mitchell 2003-09-07 23:52:21 UTC
Fixed in GCC 3.3.2, GCC 3.4.