Bug 43024 - [4.4 Regression] ICE on template code with -O2 or -O3, regression from 4.4.2
Summary: [4.4 Regression] ICE on template code with -O2 or -O3, regression from 4.4.2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.3
: P1 normal
Target Milestone: 4.4.4
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-10 19:32 UTC by Thomas Capricelli
Modified: 2010-02-15 04:02 UTC (History)
4 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build:
Known to work: 4.5.0
Known to fail: 4.4.0 4.4.3 4.4.4
Last reconfirmed: 2010-02-11 13:26:10


Attachments
as provided by -save-temps (182.74 KB, application/octet-stream)
2010-02-10 19:33 UTC, Thomas Capricelli
Details
delta-reduced testcase (6.04 KB, application/x-bzip2)
2010-02-12 22:21 UTC, Jason Merrill
Details
ice16.ii (4.76 KB, text/plain)
2010-02-12 23:09 UTC, Jakub Jelinek
Details
Further reduced testcase (255 bytes, text/plain)
2010-02-14 21:52 UTC, Volker Reichelt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Capricelli 2010-02-10 19:32:08 UTC
Upgrading from 4.4.2 to 4.4.3, gcc now segfaults when compiling my file. I've narrowed both the command line and the cpp file (30 lines, visible at the end of the *.ii attached). Most of the included code is from eigen (http://eigen.tuxfamily.org/) and is publicly visible on 
http://bitbucket.org/eigen/eigen

When compiled with -O2 or -O3 the segfaults is triggered, without -O option, the file compiles fine.

The complete line i use is:
g++ -c -O3 -I../../eigen2-tip -o ice.o ice.cpp -save-temps

The output is:
----------------------------------------------------------------------------
In file included from ../../eigen2-tip/Eigen/Core:178,
                 from ../../eigen2-tip/unsupported/Eigen/NonLinearOptimization:29,
                 from ice.cpp:3:
../../eigen2-tip/Eigen/src/Core/DenseStorageBase.h: In member function ‘Eigen::LevenbergMarquardtSpace::Status Eigen::LevenbergMarquardt<FunctorType, Scalar>::minimizeOneStep(Eigen::Matrix<Scalar, 33331, 1, 0, 33331, 1>&, int) [with FunctorType = myFunctor, Scalar = double]’:            
../../eigen2-tip/Eigen/src/Core/DenseStorageBase.h:516: internal compiler error: Segmentation fault
Please submit a full bug report, with preprocessed source if appropriate.
See <http://bugs.gentoo.org/> for instructions.  
----------------------------------------------------------------------------

The output of gcc -v is (i'm using gentoo) :
----------------------------------------------------------------------------
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: /usr/data/tmp/portage/sys-devel/gcc-4.4.3/work/gcc-4.4.3/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.4.3 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/python --disable-libgcj --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.4.3 p1.0'
Thread model: posix
gcc version 4.4.3 (Gentoo 4.4.3 p1.0)
----------------------------------------------------------------------------
Comment 1 Thomas Capricelli 2010-02-10 19:33:10 UTC
Created attachment 19836 [details]
as provided by -save-temps
Comment 2 H.J. Lu 2010-02-11 03:20:37 UTC
It is caused by revision 153881:

http://gcc.gnu.org/ml/gcc-cvs/2009-11/msg00097.html
Comment 3 Richard Biener 2010-02-11 10:04:39 UTC
Confirmed.  Works on the trunk.
Comment 4 Jason Merrill 2010-02-12 22:19:41 UTC
This is basically the same bug as PR 41183.

We crash when trying to do name lookup during template substitution during mangling during compilation of a clone. Cloning doesn't copy cfun->language, so current_binding_level tries to look inside it and SEGVs.
Comment 5 Jason Merrill 2010-02-12 22:21:37 UTC
Created attachment 19854 [details]
delta-reduced testcase

this testcase is a lot smaller, but still not as reduced as I'd like
Comment 6 Jason Merrill 2010-02-12 22:27:20 UTC
Subject: Bug 43024

Author: jason
Date: Fri Feb 12 22:27:04 2010
New Revision: 156740

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156740
Log:
	PR c++/43024
	* name-lookup.h (current_binding_level): Check for null
	cp_function_chain.

Modified:
    branches/gcc-4_4-branch/gcc/cp/ChangeLog
    branches/gcc-4_4-branch/gcc/cp/name-lookup.h

Comment 7 Jason Merrill 2010-02-12 22:27:28 UTC
Subject: Bug 43024

Author: jason
Date: Fri Feb 12 22:27:14 2010
New Revision: 156741

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156741
Log:
	PR c++/43024
	* name-lookup.h (current_binding_level): Check for null
	cp_function_chain.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/name-lookup.h

Comment 8 Jakub Jelinek 2010-02-12 23:09:44 UTC
Created attachment 19855 [details]
ice16.ii

Slightly reduced testcase using some more delta, I'm afraid now needs some manual work to help further reduction and don't have time for that right now.
Comment 9 Volker Reichelt 2010-02-14 21:52:51 UTC
Created attachment 19865 [details]
Further reduced testcase
Comment 10 Volker Reichelt 2010-02-14 21:54:50 UTC
The reduced testcase from comment #9 crashes with -O2 on i686-pc-linux-gnu
since GCC 4.4.0, so the problem is not a regression from 4.4.2, but from 4.3.x.
Comment 11 Jason Merrill 2010-02-15 04:01:28 UTC
Subject: Bug 43024

Author: jason
Date: Mon Feb 15 04:01:10 2010
New Revision: 156766

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156766
Log:
	PR c++/43024
	* g++.dg/opt/ice1.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/opt/ice1.C
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 12 Jason Merrill 2010-02-15 04:02:18 UTC
Testcase added to testsuite, thanks a lot.
Comment 13 Jie Zhang 2010-03-26 14:31:04 UTC
Subject: Bug 43024

Author: jiez
Date: Fri Mar 26 14:30:49 2010
New Revision: 157750

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157750
Log:
2010-03-26  Volker Reichelt  <reichelt@gcc.gnu.org>

	PR c++/43024
	* g++.dg/opt/ice1.C: New.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/opt/ice1.C
Modified:
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog