public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-8893] dwarf2out: Emit DW_AT_location for global register vars during early dwarf [PR101905]
Date: Mon, 23 Aug 2021 09:55:58 +0000 (GMT)	[thread overview]
Message-ID: <20210823095558.B3C9C385501B@sourceware.org> (raw)

https://gcc.gnu.org/g:513c543bb5d97cc59ba393f2f0612324a789c50e

commit r11-8893-g513c543bb5d97cc59ba393f2f0612324a789c50e
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Aug 23 11:50:14 2021 +0200

    dwarf2out: Emit DW_AT_location for global register vars during early dwarf [PR101905]
    
    The following patch emits DW_AT_location for global register variables
    already during early dwarf, since usually late_global_decl hook isn't even
    called for those, as nothing needs to be emitted for them.
    
    2021-08-23  Jakub Jelinek  <jakub@redhat.com>
    
            PR debug/101905
            * dwarf2out.c (gen_variable_die): Add DW_AT_location for global
            register variables already during early_dwarf if possible.
    
            * gcc.dg/guality/pr101905.c: New test.
    
    (cherry picked from commit b284053bb75661fc1bf13c275f3ba5364bb17608)

Diff:
---
 gcc/dwarf2out.c                         | 21 ++++++++++++++++++++-
 gcc/testsuite/gcc.dg/guality/pr101905.c | 15 +++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 54c6c326d49..7296cdb52fb 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -24254,7 +24254,26 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
 	      && DECL_RTL_SET_P (decl_or_origin))))
     {
       if (early_dwarf)
-	add_pubname (decl_or_origin, var_die);
+	{
+	  add_pubname (decl_or_origin, var_die);
+	  /* For global register variables, emit DW_AT_location if possible
+	     already during early_dwarf, as late_global_decl won't be usually
+	     called.  */
+	  if (DECL_HARD_REGISTER (decl_or_origin)
+	      && TREE_STATIC (decl_or_origin)
+	      && !decl_by_reference_p (decl_or_origin)
+	      && !get_AT (var_die, DW_AT_location)
+	      && !get_AT (var_die, DW_AT_const_value)
+	      && DECL_RTL_SET_P (decl_or_origin)
+	      && REG_P (DECL_RTL (decl_or_origin)))
+	    {
+	      dw_loc_descr_ref descr
+		= reg_loc_descriptor (DECL_RTL (decl_or_origin),
+				      VAR_INIT_STATUS_INITIALIZED);
+	      if (descr)
+		add_AT_loc (var_die, DW_AT_location, descr);
+	    }
+	}
       else
 	add_location_or_const_value_attribute (var_die, decl_or_origin,
 					       decl == NULL);
diff --git a/gcc/testsuite/gcc.dg/guality/pr101905.c b/gcc/testsuite/gcc.dg/guality/pr101905.c
new file mode 100644
index 00000000000..71b7516905b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/guality/pr101905.c
@@ -0,0 +1,15 @@
+/* { dg-do run { target { { i?86-*-* x86_64-*-* } && lp64 } } } */
+/* { dg-options "-g -ffixed-r15" } */
+/* { dg-skip-if "" { *-*-* }  { "*" } { "-O0" } } */
+
+register unsigned long long regVar asm ("r15");
+
+int
+main()
+{
+  regVar = 0xdeadbeefcafebabeULL;
+  asm ("nop" : "+r" (regVar));
+  asm volatile ("nop");		/* { dg-final { gdb-test . "regVar" "0xdeadbeefcafebabeULL" } } */
+  asm volatile ("nop" : : "r" (regVar));
+  return 0;
+}


                 reply	other threads:[~2021-08-23  9:55 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=20210823095558.B3C9C385501B@sourceware.org \
    --to=jakub@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).