--- Comment #8 from pmderodat at gcc dot ---
Author: pmderodat
Date: Sat Aug 12 09:07:12 2017
New Revision: 251066

[PR79542][Ada] Fix ICE in dwarf2out.c with nested func. inlining reports an ICE in
dwarf2out.c for an Ada testcase built with optimization.

This crash happens during the late generation pass because
add_gnat_descriptive_type cannot find the type DIE corresponding to some
descriptive type after having tried to generate it. This is because the
DIE was generated during the early generation pass, but then pruned by
the type pruning machinery. So why was it pruned?

We are in a situation where we have cloned types (because of inlining,
IIUC) whose TYPE_NAME have non-null DECL_ABSTRACT_ORIGIN attributes. As
a consequence:

  * In modified_type_die, the "handle C typedef types" part calls
    gen_type_die on the cloned type.

  * gen_type_die matches a typedef variant, and then calls gen_decl_die
    on its TYPE_NAME, which will end up calling gen_typedef_die.

  * gen_typedef_die checks decl_ultimate_origin for this TYPE_DECL, and
    finds one, so it only adds a DW_AT_abstract_origin attribute to the
    DW_TAG_typedef DIE, but the cloned type itself does not get its own

  * Back in modified_type_die, the call to lookup_type_die on the type
    passed to gen_type_die returns NULL.

In the end, whole type trees, i.e. the ones referenced by
DECL_ABSTRACT_ORIGIN attributes, are never referenced from type pruning
"roots" and are thus pruned. The descriptive type at stake here is one
of them, hence the assertion failure.

This patch attemps to fix that with what seems to be the most sensible
thing to do in my opinion: updating the "handle C typedef types" part in
modified_type_die to check decl_ultimate_origin before calling
gen_type_die: if that function returns something not null, then we know
that gen_type_die/gen_typedef_die will not generate a DIE for the input
type, so we try to process the ultimate origin instead. It also updates
in a similar way gen_type_die_with_usage, assert that when
gen_typedef_die is called on nodes that have an ultimate origin, this
origin is themselves.

        PR ada/79542
        * dwarf2out.c (modified_type_die): For C typedef types that have
        an ultimate origin, process the ultimate origin instead of the
        input type.
        (gen_typedef_die): Assert that input DECLs have no ultimate
        (gen_type_die_with_usage): For typedef variants that have an
        ultimate origin, just call gen_decl_die on the original DECL.
        (process_scope_var): Avoid creating DIEs for local typedefs and
        concrete static variables.


        PR ada/79542
        * gnat.dg/, gnat.dg/debug13.adb: New testcase.


Reply via email to