Created attachment 30955 [details] preprocessed file gcc 4.8.1 segfaults while compiling code with templated static thread_local storage. Compiler output: $ gcc -v -std=c++0x -save-temps test.cpp Reading specs from /usr/lib64/gcc/x86_64-redhat-linux-gnu/4.8.1/specs COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/gcc/4.8.1/libexec/gcc/x86_64-redhat-linux-gnu/4.8.1/lto-wrapper Target: x86_64-redhat-linux-gnu Configured with: ./configure --prefix=/usr/local/gcc/4.8.1 --build=x86_64-redhat-linux-gnu --libdir=/usr/lib64 --with-slibdir=/usr/lib64 --enable-version-specific-runtime-libs --enable-threads --enable-static --enable-languages=c,c++ --disable-multilib --with-cloog=/tmp/gcc-deps --enable-cloog-backend=isl --disable-cloog-version-check Thread model: posix gcc version 4.8.1 (GCC) COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-save-temps' '-mtune=generic' '-march=x86-64' /usr/local/gcc/4.8.1/libexec/gcc/x86_64-redhat-linux-gnu/4.8.1/cc1plus -E -quiet -v -D_GNU_SOURCE test.cpp -mtune=generic -march=x86-64 -std=c++11 -fpch-preprocess -o test.ii ignoring nonexistent directory "/usr/lib64/gcc/x86_64-redhat-linux-gnu/4.8.1/../../../../../x86_64-redhat-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: . /pubmed_gen/Work/boost/include /usr/lib64/gcc/x86_64-redhat-linux-gnu/4.8.1/include/c++ /usr/lib64/gcc/x86_64-redhat-linux-gnu/4.8.1/include/c++/x86_64-redhat-linux-gnu /usr/lib64/gcc/x86_64-redhat-linux-gnu/4.8.1/include/c++/backward /usr/lib64/gcc/x86_64-redhat-linux-gnu/4.8.1/include /usr/local/include /usr/local/gcc/4.8.1/include /usr/lib64/gcc/x86_64-redhat-linux-gnu/4.8.1/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-save-temps' '-mtune=generic' '-march=x86-64' /usr/local/gcc/4.8.1/libexec/gcc/x86_64-redhat-linux-gnu/4.8.1/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -std=c++11 -version -o test.s GNU C++ (GCC) version 4.8.1 (x86_64-redhat-linux-gnu) compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++ (GCC) version 4.8.1 (x86_64-redhat-linux-gnu) compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 4dcc0c9a463b0607e2149021eec6a2a8 test.cpp: In function 'std::unique_ptr<std::basic_string<char> >& _ZTWN1AIT_E1sE()': test.cpp:10:18: internal compiler error: Segmentation fault if (!s) { ^ Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions.
Created attachment 30956 [details] source file Added small source file that reproduces the bug.
Doesn't look like a C++ front-end issue.
Confirmed. Also happens on trunk. t.C: In function 'std::unique_ptr<std::basic_string<char> >& _ZTWN1AIT_E1sE()': t.C:10:7: internal compiler error: Segmentation fault if (!s) { ^ 0xc67bdd crash_signal /space/rguenther/src/svn/gcc-4_8-branch/gcc/toplev.c:332 0x563d74 tree_check(tree_node const*, char const*, int, char const*, tree_code) /space/rguenther/src/svn/gcc-4_8-branch/gcc/tree.h:3893 0xea90f1 decl_assembler_name_hash(tree_node const*) /space/rguenther/src/svn/gcc-4_8-branch/gcc/tree.c:601 0x89636a insert_to_assembler_name_hash /space/rguenther/src/svn/gcc-4_8-branch/gcc/symtab.c:118 0x89661a symtab_register_node(symtab_node_def*) /space/rguenther/src/svn/gcc-4_8-branch/gcc/symtab.c:199 0xf0c8c5 varpool_node_for_decl(tree_node*) /space/rguenther/src/svn/gcc-4_8-branch/gcc/varpool.c:52
Started by r192211.
*** Bug 62268 has been marked as a duplicate of this bug. ***
*** Bug 61558 has been marked as a duplicate of this bug. ***
For 5: markus@x4 tmp % cat boo.ii static __typeof 0 a __attribute__ ((__weakref__ (""))); template <typename> class A { static __thread int b; }; markus@x4 tmp % g++ -std=c++11 boo.ii boo.ii:5:2: internal compiler error: Segmentation fault }; ^ 0xbbfe5f crash_signal ../../gcc/gcc/toplev.c:339 0x856964 tree_check ../../gcc/gcc/tree.h:2962 0x856964 symbol_table::decl_assembler_name_hash(tree_node const*) ../../gcc/gcc/symtab.c:69 0x856c13 symbol_table::insert_to_assembler_name_hash(symtab_node*, bool) ../../gcc/gcc/symtab.c:181 0x856d5c symbol_table::symtab_initialize_asm_name_hash() ../../gcc/gcc/symtab.c:263 0x858414 symbol_table::symtab_initialize_asm_name_hash() ../../gcc/gcc/symtab.c:958 0x858414 symtab_node::get_for_asmname(tree_node const*) ../../gcc/gcc/symtab.c:947 0x864d80 handle_alias_pairs ../../gcc/gcc/cgraphunit.c:1111 0x869d8c symbol_table::finalize_compilation_unit() ../../gcc/gcc/cgraphunit.c:2264 0x656d6a cp_write_global_declarations() ../../gcc/gcc/cp/decl2.c:4666 Please submit a full bug report, with preprocessed source if appropriate. for 4.8, 4.9 and 5: markus@x4 tmp % cat test.ii namespace std { typedef int string; template <typename> class unique_ptr; } template <typename> class A { static thread_local std::unique_ptr<std::string> s; public: A () { s; } }; int main () { A<void> a; } markus@x4 tmp % g++ -std=c++11 test.ii cc1plus: internal compiler error: Segmentation fault 0xbbfe5f crash_signal ../../gcc/gcc/toplev.c:339 0x856964 tree_check ../../gcc/gcc/tree.h:2962 0x856964 symbol_table::decl_assembler_name_hash(tree_node const*) ../../gcc/gcc/symtab.c:69 0x856c13 symbol_table::insert_to_assembler_name_hash(symtab_node*, bool) ../../gcc/gcc/symtab.c:181 0x856d5c symbol_table::symtab_initialize_asm_name_hash() ../../gcc/gcc/symtab.c:263 0x8699d2 analyze_functions ../../gcc/gcc/cgraphunit.c:1094 0x869da5 symbol_table::finalize_compilation_unit() ../../gcc/gcc/cgraphunit.c:2277 0x656d6a cp_write_global_declarations() ../../gcc/gcc/cp/decl2.c:4666 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions.
(In reply to Markus Trippelsdorf from comment #7) > static __typeof 0 a __attribute__ ((__weakref__ (""))); > template <typename> class A > { > static __thread int b; > }; The problem with this testcase is that set_decl_tls_model adds A<T>::b, an uninstantiated template, to the symbol table. This ICE was introduced by honza's r211689. I'll deal with the other testcase.
Author: jason Date: Tue Aug 26 19:39:36 2014 New Revision: 214543 URL: https://gcc.gnu.org/viewcvs?rev=214543&root=gcc&view=rev Log: PR c++/58624 * pt.c (tsubst_decl) [VAR_DECL]: Copy TLS model. (tsubst_copy_and_build) [VAR_DECL]: Use TLS wrapper. * semantics.c (finish_id_expression): Don't call TLS wrapper in a template. Added: trunk/gcc/testsuite/g++.dg/tls/thread_local10.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/cp/semantics.c
Author: jason Date: Tue Aug 26 20:05:13 2014 New Revision: 214546 URL: https://gcc.gnu.org/viewcvs?rev=214546&root=gcc&view=rev Log: PR c++/58624 * pt.c (tsubst_copy_and_build) [VAR_DECL]: Use TLS wrapper. * semantics.c (finish_id_expression): Don't call TLS wrapper in a template. Added: branches/gcc-4_9-branch/gcc/testsuite/g++.dg/tls/thread_local10.C Modified: branches/gcc-4_9-branch/gcc/cp/ChangeLog branches/gcc-4_9-branch/gcc/cp/pt.c branches/gcc-4_9-branch/gcc/cp/semantics.c
Fixed for 4.9.2. Still broken on trunk because of the set_decl_tls_model issue, which I will leave to honza.
Author: jason Date: Wed Oct 15 16:46:11 2014 New Revision: 216273 URL: https://gcc.gnu.org/viewcvs?rev=216273&root=gcc&view=rev Log: PR c++/58624 * pt.c (tsubst_copy_and_build) [VAR_DECL]: Use TLS wrapper. * semantics.c (finish_id_expression): Don't call TLS wrapper in a template. Added: branches/gcc-4_8-branch/gcc/testsuite/g++.dg/tls/thread_local10.C Modified: branches/gcc-4_8-branch/gcc/cp/ChangeLog branches/gcc-4_8-branch/gcc/cp/pt.c branches/gcc-4_8-branch/gcc/cp/semantics.c
Note the thread_local10.C test fails on the 4.8 branch. The problem is that the 4.8 branch doesn't contain the https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/testsuite/g%2B%2B.dg/plugin/plugin.exp?r1=208416&r2=208415&pathrev=208416&limit_changes=0&view=patch the change and thus if plugin.exp is run before tls.exp, the default flags include -ansi. Jason, do you think that change (just the plugin.exp one) is ok for 4.8.4, or alternatively we can add something like // { dg-options "" } to the test.
(In reply to Jakub Jelinek from comment #13) > Jason, do you think that change (just the plugin.exp one) is ok for 4.8.4, Yes, that should be fine.
Author: jakub Date: Mon Dec 15 10:36:16 2014 New Revision: 218739 URL: https://gcc.gnu.org/viewcvs?rev=218739&root=gcc&view=rev Log: PR middle-end/58624 Backported from mainline 2014-03-07 Jason Merrill <jason@redhat.com> * g++.dg/plugin/plugin.exp (DEFAULT_CXXFLAGS): Remove -ansi. Modified: branches/gcc-4_8-branch/gcc/testsuite/ChangeLog branches/gcc-4_8-branch/gcc/testsuite/g++.dg/plugin/plugin.exp
Author: jakub Date: Mon Dec 15 10:47:14 2014 New Revision: 218741 URL: https://gcc.gnu.org/viewcvs?rev=218741&root=gcc&view=rev Log: PR middle-end/58624 Backported from mainline 2014-03-07 Jason Merrill <jason@redhat.com> * g++.dg/plugin/plugin.exp (DEFAULT_CXXFLAGS): Remove -ansi. Modified: branches/gcc-4_9-branch/gcc/testsuite/ChangeLog branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/ipa/pr63551.c
Can the bug be marked as resolved?
(In reply to Jason Merrill from comment #8) > (In reply to Markus Trippelsdorf from comment #7) > > static __typeof 0 a __attribute__ ((__weakref__ (""))); > > template <typename> class A > > { > > static __thread int b; > > }; > > The problem with this testcase is that set_decl_tls_model adds A<T>::b, an > uninstantiated template, to the symbol table. This ICE was introduced by > honza's r211689. > > I'll deal with the other testcase. which seems like was fixed with r6-1888: @@ -2523,8 +2523,12 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) } if (VAR_P (newdecl) - && DECL_THREAD_LOCAL_P (newdecl)) - set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl)); + && CP_DECL_THREAD_LOCAL_P (newdecl)) + { + CP_DECL_THREAD_LOCAL_P (olddecl) = true; + if (!processing_template_decl) + set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl)); + } }