https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82155

--- Comment #8 from pmderodat at gcc dot gnu.org ---
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

Reply via email to