The crash is extracted from ceph-10.2.9. [1] is the minimal reproducer (a bit big as I did not clean it after 'creduce'): Crashes on both gcc-7.2.0 anf gcc-master (x86_64-pc-linux-gnu) $ LANG=C g++ -O2 -g -c -o ECBackend.o ECBackend.ii ECBackend.ii: In member function 'virtual void m::m()::n::k(int)': ECBackend.ii:23:12: internal compiler error: in force_type_die, at dwarf2out.c:25099 void k(int) {} ^ Please submit a full bug report, with preprocessed source if appropriate. See <https://bugs.gentoo.org/> for instructions. // [1] : reproducer template <typename a> struct b { a c; }; template <typename d> struct e { d *operator->(); }; template <typename d> class h { public: typedef e<d> ag; }; class i { protected: i(int); }; class j { virtual void k(int) = 0; public: int f; void l() { k(f); } }; struct m : i { int cn; m() : i(cn) { struct n : j { n() {} void k(int) {} }; } }; struct o { o() { for (h<b<b<j *>>>::ag g;;) g->c.c->l(); } }; void fn1() { o(); }
Created attachment 42143 [details] ECBackend.ii Attaching original reproducer as well.
Started with r242035
Thank you for reporting this. I’m having a look.
I have a candidate fix, which I submitted on gcc-patches@: <https://gcc.gnu.org/ml/gcc-patches/2017-09/msg00647.html>
Author: pmderodat Date: Mon Sep 25 12:26:36 2017 New Revision: 253147 URL: https://gcc.gnu.org/viewcvs?rev=253147&root=gcc&view=rev Log: [PR82155] Fix crash in dwarf2out_abstract_function This patch is an attempt to fix the crash reported in PR82155. When generating a C++ class method for a class that is itself nested in a class method, dwarf2out_early_global_decl currently leaves the existing context DIE as it is if it already exists. However, it is possible that this call happens at a point where this context DIE is just a declaration that is itself not located in its own context. From there, if dwarf2out_early_global_decl is not called on any of the FUNCTION_DECL in the context chain, DIEs will be left badly scoped and some (such as the nested method) will be removed by the type pruning machinery. As a consequence, dwarf2out_abstract_function will will crash when called on the corresponding DECL because it asserts that the DECL has a DIE. This patch fixes this crash making dwarf2out_early_global_decl process context DIEs the same way we process abstract origins for FUNCTION_DECL: if the corresponding DIE exists but is only a declaration, call dwarf2out_decl anyway on it so that it is turned into a more complete DIE and so that it is relocated in the proper context. Bootstrapped and regtested on x86_64-linux. gcc/ PR debug/82155 * dwarf2out.c (dwarf2out_early_global_decl): Call dwarf2out_decl on the FUNCTION_DECL function context if it has a DIE that is a declaration. gcc/testsuite/ * g++.dg/pr82155.C: New testcase. Added: trunk/gcc/testsuite/g++.dg/pr82155.C Modified: trunk/gcc/ChangeLog trunk/gcc/dwarf2out.c trunk/gcc/testsuite/ChangeLog
Assuming fixed on the trunk.
*** Bug 82998 has been marked as a duplicate of this bug. ***
Author: pmderodat Date: Wed Nov 15 11:54:11 2017 New Revision: 254761 URL: https://gcc.gnu.org/viewcvs?rev=254761&root=gcc&view=rev Log: [PATCH] [PR82155] Fix crash in dwarf2out_abstract_function Backport from mainline (r253147): This patch is an attempt to fix the crash reported in PR82155. When generating a C++ class method for a class that is itself nested in a class method, dwarf2out_early_global_decl currently leaves the existing context DIE as it is if it already exists. However, it is possible that this call happens at a point where this context DIE is just a declaration that is itself not located in its own context. From there, if dwarf2out_early_global_decl is not called on any of the FUNCTION_DECL in the context chain, DIEs will be left badly scoped and some (such as the nested method) will be removed by the type pruning machinery. As a consequence, dwarf2out_abstract_function will will crash when called on the corresponding DECL because it asserts that the DECL has a DIE. This patch fixes this crash making dwarf2out_early_global_decl process context DIEs the same way we process abstract origins for FUNCTION_DECL: if the corresponding DIE exists but is only a declaration, call dwarf2out_decl anyway on it so that it is turned into a more complete DIE and so that it is relocated in the proper context. Bootstrapped and regtested on x86_64-linux. gcc/ PR debug/82155 * dwarf2out.c (dwarf2out_early_global_decl): Call dwarf2out_decl on the FUNCTION_DECL function context if it has a DIE that is a declaration. gcc/testsuite/ * g++.dg/pr82155.C: New testcase. Added: branches/gcc-7-branch/gcc/testsuite/g++.dg/pr82155.C Modified: branches/gcc-7-branch/gcc/ChangeLog branches/gcc-7-branch/gcc/dwarf2out.c branches/gcc-7-branch/gcc/testsuite/ChangeLog
Fix is on trunk and I just merged it in the gcc-7 branch. I’ve left the target milestone to 7.3 even though 7.4 is available since according to https://gcc.gnu.org/gcc-7/, the last release was 7.2. Hoping I got it right!
*** Bug 84736 has been marked as a duplicate of this bug. ***