Bug 23180 - [4.1 regression] Segfault on const initializer with bogus pointer arithmetics
Summary: [4.1 regression] Segfault on const initializer with bogus pointer arithmetics
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2005-08-01 14:22 UTC by Falk Hueffner
Modified: 2005-09-09 03:13 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-08-01 14:35:51


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Falk Hueffner 2005-08-01 14:22:50 UTC
falk@juist:/tmp% cat bug.cc   
void saveLoadEntries(const void *);
void saveOrLoad() {
    struct Track {
        char soundName[15];
    };
    struct SaveLoadEntry {
        int offs;
        int type;
        int size;
    };    
    const SaveLoadEntry trackEntries = {
        ((long) (&((Track *) 42)->soundName[0])) - 42,
        0, 1
    };
    saveLoadEntries(&trackEntries);
}

falk@juist:/tmp% g++ -c bug.cc
bug.cc:15: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

In case anyone wonders, this comes from:
// * To work around a warning in GCC 3.2 (and 3.1 ?) regarding non-POD types[...]
#define OFFS(type,item) (((long)(&((type*)42)->type::item))-42)

This is of course invalid, but it'd be nice if it did what those folks wanted.
Comment 1 Andrew Pinski 2005-08-01 14:35:51 UTC
Confirmed, a regression from 4.0.0.
Comment 2 Andrew Pinski 2005-08-01 14:36:15 UTC
Here is the backtrace:
#1  0x08423014 in expand_binop (mode=SImode, binoptab=0xb7cb4600, op0=0xb7cac360, 
op1=0xb7cac0c0, target=0x0, unsignedp=1, 
    methods=OPTAB_LIB_WIDEN) at /home/peshtigo/pinskia/src/gnu/gcc/src/gcc/optabs.c:1028
#2  0x082f9625 in expand_expr_addr_expr_1 (exp=Variable "exp" is not available.
) at /home/peshtigo/pinskia/src/gnu/gcc/src/gcc/expr.c:6310
#3  0x082ec524 in expand_expr_real_1 (exp=0xb7d2b4c0, target=0x0, tmode=SImode, 
modifier=Variable "modifier" is not available.
)
    at /home/peshtigo/pinskia/src/gnu/gcc/src/gcc/expr.c:6349
#4  0x082f5cbe in expand_expr_real (exp=0xb7d2b4c0, target=0x0, tmode=VOIDmode, 
modifier=EXPAND_INITIALIZER, alt_rtl=0x0)
    at /home/peshtigo/pinskia/src/gnu/gcc/src/gcc/expr.c:6462
#5  0x084b6180 in output_constant (exp=0xb7d2b4c0, size=4, align=32) at expr.h:492
#6  0x084b5308 in output_constructor (exp=0xb7d4f900, size=12, align=32)
Comment 3 GCC Commits 2005-09-09 01:37:41 UTC
Subject: Bug 23180

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jconner@gcc.gnu.org	2005-09-09 01:37:31

Modified files:
	gcc            : ChangeLog expr.c 

Log message:
	PR c++/23180
	* expr.c (expand_expr_addr_expr_1): Don't invoke
	expand_simple_binop for EXPAND_INITIALIZER.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9921&r2=2.9922
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expr.c.diff?cvsroot=gcc&r1=1.815&r2=1.816

Comment 4 GCC Commits 2005-09-09 01:39:42 UTC
Subject: Bug 23180

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jconner@gcc.gnu.org	2005-09-09 01:39:36

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/init: pr23180-1.C pr23180-2.C 

Log message:
	PR c++/23180
	* g++.dg/init/pr23180-1.C: New test.
	* g++.dg/init/pr23180-2.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6034&r2=1.6035
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/pr23180-1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/pr23180-2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 Andrew Pinski 2005-09-09 03:13:12 UTC
Fixed.
Comment 6 GCC Commits 2005-09-14 00:25:22 UTC
Subject: Bug 23180

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jconner@gcc.gnu.org	2005-09-14 00:25:02

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/init: struct2.C struct3.C 

Log message:
	PR c++/23180
	* g++.dg/init/struct2.C: New test.
	* g++.dg/init/struct3.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6061&r2=1.6062
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/struct2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/struct3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1