From e2f3057fc911f9f55986b3de237b0155c0e09fe8 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 23 Jan 2024 09:51:00 +0100 Subject: debug/107058 - gracefully handle unexpected DIE contexts While the bug is persisting that LTO streaming picks up a CONST_DECL from an attribute argument on a VAR_DECL which with -fdebug-type-section refers to a DIE in a type unit we can handle this gracefully, at least with -fno-checking. Do so. The C++ frontend nevetheless should resolve the CONST_DECL attribute argument to a constant. PR debug/107058 * dwarf2out.cc (dwarf2out_die_ref_for_decl): Gracefully handle unexpected but bogus DIE contexts when not checking enabled. * c-c++-common/pr107058.c: New testcase. --- gcc/dwarf2out.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gcc/dwarf2out.cc') diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 0b8a300..2b72321 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -6061,10 +6061,17 @@ dwarf2out_die_ref_for_decl (tree decl, const char **sym, die = die->die_parent; /* For the containing CU DIE we compute a die_symbol in compute_comp_unit_symbol. */ - gcc_assert (die->die_tag == DW_TAG_compile_unit - && die->die_id.die_symbol != NULL); - *sym = die->die_id.die_symbol; - return true; + if (die->die_tag == DW_TAG_compile_unit) + { + gcc_assert (die->die_id.die_symbol != NULL); + *sym = die->die_id.die_symbol; + return true; + } + /* While we can gracefully handle running into say a type unit + we don't really want and consider this a bug. */ + if (flag_checking) + gcc_unreachable (); + return false; } /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE. */ -- cgit v1.1