Bug 45008 - [4.5 Regression] Template code not expanded properly
Summary: [4.5 Regression] Template code not expanded properly
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.0
: P2 normal
Target Milestone: 4.5.1
Assignee: Jason Merrill
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-07-20 18:35 UTC by Martin Gieseking
Modified: 2010-07-23 13:51 UTC (History)
3 users (show)

See Also:
Host: x86_64-suse-linux
Target: x86_64-suse-linux
Build: x86_64-suse-linux
Known to work:
Known to fail:
Last reconfirmed: 2010-07-22 19:23:51


Attachments
sources to reproduce the issue (120.50 KB, application/x-gzip)
2010-07-20 18:37 UTC, Martin Gieseking
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Gieseking 2010-07-20 18:35:40 UTC
When compiling the attached sources with gcc 4.5.0 on Linux x86_64, I get an executable that unexpectedly leads to a segfault. It seems, gcc doesn't handle sub-classes defined and instantiated in a template's method properly.

I've attached a tarball containing the 3 files f1.ii, f2.ii, and main.ii.

Here's the compiler output:

$ g++ -v -save-temps f1.cpp f2.cpp main.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.5/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.5 --enable-ssp --disable-libssp --disable-plugin --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.5 --enable-linux-futex --without-system-libunwind --enable-gold --with-plugin-ld=/usr/bin/gold --with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.5.0 20100604 [gcc-4_5-branch revision 160292] (SUSE Linux) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.5/cc1plus -E -quiet -v -D_GNU_SOURCE f1.cpp -mtune=generic -march=x86-64 -fpch-preprocess -o f1.ii
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.5
 /usr/include/c++/4.5/x86_64-suse-linux
 /usr/include/c++/4.5/backward
 /usr/local/include
 /usr/lib64/gcc/x86_64-suse-linux/4.5/include
 /usr/lib64/gcc/x86_64-suse-linux/4.5/include-fixed
 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.5/cc1plus -fpreprocessed f1.ii -quiet -dumpbase f1.cpp -mtune=generic -march=x86-64 -auxbase f1 -version -o f1.s
GNU C++ (SUSE Linux) version 4.5.0 20100604 [gcc-4_5-branch revision 160292] (x86_64-suse-linux)
	compiled by GNU C version 4.5.0 20100604 [gcc-4_5-branch revision 160292], GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127782
GNU C++ (SUSE Linux) version 4.5.0 20100604 [gcc-4_5-branch revision 160292] (x86_64-suse-linux)
	compiled by GNU C version 4.5.0 20100604 [gcc-4_5-branch revision 160292], GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127782
Compiler executable checksum: 5c8e9dc17442c61d1650fc721fc13e48
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/as -V -Qy --64 -o f1.o f1.s
GNU assembler version 2.20.0 (x86_64-suse-linux) using BFD version (GNU Binutils; openSUSE 11.3) 2.20.0.20100122-6
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.5/cc1plus -E -quiet -v -D_GNU_SOURCE f2.cpp -mtune=generic -march=x86-64 -fpch-preprocess -o f2.ii
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.5
 /usr/include/c++/4.5/x86_64-suse-linux
 /usr/include/c++/4.5/backward
 /usr/local/include
 /usr/lib64/gcc/x86_64-suse-linux/4.5/include
 /usr/lib64/gcc/x86_64-suse-linux/4.5/include-fixed
 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.5/cc1plus -fpreprocessed f2.ii -quiet -dumpbase f2.cpp -mtune=generic -march=x86-64 -auxbase f2 -version -o f2.s
GNU C++ (SUSE Linux) version 4.5.0 20100604 [gcc-4_5-branch revision 160292] (x86_64-suse-linux)
	compiled by GNU C version 4.5.0 20100604 [gcc-4_5-branch revision 160292], GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127782
GNU C++ (SUSE Linux) version 4.5.0 20100604 [gcc-4_5-branch revision 160292] (x86_64-suse-linux)
	compiled by GNU C version 4.5.0 20100604 [gcc-4_5-branch revision 160292], GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127782
Compiler executable checksum: 5c8e9dc17442c61d1650fc721fc13e48
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/as -V -Qy --64 -o f2.o f2.s
GNU assembler version 2.20.0 (x86_64-suse-linux) using BFD version (GNU Binutils; openSUSE 11.3) 2.20.0.20100122-6
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.5/cc1plus -E -quiet -v -D_GNU_SOURCE main.cpp -mtune=generic -march=x86-64 -fpch-preprocess -o main.ii
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.5
 /usr/include/c++/4.5/x86_64-suse-linux
 /usr/include/c++/4.5/backward
 /usr/local/include
 /usr/lib64/gcc/x86_64-suse-linux/4.5/include
 /usr/lib64/gcc/x86_64-suse-linux/4.5/include-fixed
 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.5/cc1plus -fpreprocessed main.ii -quiet -dumpbase main.cpp -mtune=generic -march=x86-64 -auxbase main -version -o main.s
GNU C++ (SUSE Linux) version 4.5.0 20100604 [gcc-4_5-branch revision 160292] (x86_64-suse-linux)
	compiled by GNU C version 4.5.0 20100604 [gcc-4_5-branch revision 160292], GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127782
GNU C++ (SUSE Linux) version 4.5.0 20100604 [gcc-4_5-branch revision 160292] (x86_64-suse-linux)
	compiled by GNU C version 4.5.0 20100604 [gcc-4_5-branch revision 160292], GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127782
Compiler executable checksum: 5c8e9dc17442c61d1650fc721fc13e48
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/as -V -Qy --64 -o main.o main.s
GNU assembler version 2.20.0 (x86_64-suse-linux) using BFD version (GNU Binutils; openSUSE 11.3) 2.20.0.20100122-6
COMPILER_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.5/:/usr/lib64/gcc/x86_64-suse-linux/4.5/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.5/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/
LIBRARY_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.5/:/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/lib/:/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.5/collect2 --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.5/crtbegin.o -L/usr/lib64/gcc/x86_64-suse-linux/4.5 -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../.. f1.o f2.o main.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-suse-linux/4.5/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crtn.o
Comment 1 Martin Gieseking 2010-07-20 18:37:18 UTC
Created attachment 21269 [details]
sources to reproduce the issue
Comment 2 Paolo Carlini 2010-07-20 19:33:09 UTC
I can reproduce the Segmentation fault with current 4_5-branch, not with mainline.
Comment 3 Nils Schlemminger 2010-07-21 06:29:42 UTC
Same here on debian.
Comment 4 Allan McRae 2010-07-21 10:47:12 UTC
Limiting the timeframe where this became fixed on mailine:
4.5.0 20100401 fails
4.6.0 20100416 works

Comment 5 Paolo Carlini 2010-07-21 10:49:37 UTC
Jason, can you have a look to this weird issue? To repeat, I can reproduce it only in 4_5-branch, not in mainline nor in 4_4-branch (thus looks like a regression) and of course doesn't happen if a single cpp file is used.
Comment 6 Allan McRae 2010-07-22 03:53:29 UTC
Applying this commit from PR43016 to gcc-4.5 fixes the issue:
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158095
Comment 7 Jason Merrill 2010-07-23 13:51:36 UTC
Subject: Bug 45008

Author: jason
Date: Fri Jul 23 13:51:12 2010
New Revision: 162458

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162458
Log:
	PR c++/43016
	PR c++/45008
	* decl.c (start_preparsed_function): Do defer nested functions.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/g++.dg/abi/mangle44.C
Modified:
    branches/gcc-4_5-branch/gcc/cp/ChangeLog
    branches/gcc-4_5-branch/gcc/cp/decl.c
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog

Comment 8 Jason Merrill 2010-07-23 13:51:55 UTC
Fixed for 4.5.1.  Thanks for tracking down the patch that fixed it on the trunk!
Comment 9 Jason Merrill 2010-07-23 13:54:20 UTC
Subject: Bug 45008

Author: jason
Date: Fri Jul 23 13:54:01 2010
New Revision: 162459

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162459
Log:
	PR c++/45008
	* g++.dg/abi/mangle44.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/abi/mangle44.C
Modified:
    trunk/gcc/testsuite/ChangeLog