public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8351] debug/107058 - gracefully handle unexpected DIE contexts
Date: Tue, 23 Jan 2024 10:15:47 +0000 (GMT)	[thread overview]
Message-ID: <20240123101547.72A99385842A@sourceware.org> (raw)

https://gcc.gnu.org/g:e2f3057fc911f9f55986b3de237b0155c0e09fe8

commit r14-8351-ge2f3057fc911f9f55986b3de237b0155c0e09fe8
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Jan 23 09:51:00 2024 +0100

    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.

Diff:
---
 gcc/dwarf2out.cc                      | 15 +++++++++++----
 gcc/testsuite/c-c++-common/pr107058.c |  7 +++++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 0b8a3002292..2b723210f34 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.  */
diff --git a/gcc/testsuite/c-c++-common/pr107058.c b/gcc/testsuite/c-c++-common/pr107058.c
new file mode 100644
index 00000000000..5e625d6a6af
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr107058.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target lto } */
+/* { dg-options "-g -fdebug-types-section -flto -fno-checking" } */
+
+/* We should handle the C++ FE issue gracefully with -fno-checking.  */
+
+#include "pr50459.c"

                 reply	other threads:[~2024-01-23 10:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240123101547.72A99385842A@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).