* [patch] only emit one DIE for external declarations in the local scope
@ 2014-10-25 1:41 Aldy Hernandez
2014-10-27 0:49 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Aldy Hernandez @ 2014-10-25 1:41 UTC (permalink / raw)
To: gcc-patches, jason merrill
[-- Attachment #1: Type: text/plain, Size: 801 bytes --]
[Jason approved this patch off-line, and I am committing now that tests
have successfully run.]
This is a bug I found while investigating early dwarf generation, but
that is broken mainline as well.
For the following code:
namespace S
{
int i=777;
int
f()
{
int i = 42;
{
extern int i;
return i;
}
}
}
...we end up emitting an extern declaration for "i" twice, once in the
innermost lexical scope, and one in the namespace. The one in the
namespace is unnecessary (and incorrect), although it is really not
impacting any testcases since the second one is the one that takes
precedence within the innermost scope.
With this patch, we get one less DIE for this scenario on mainline,
while fixing other problems in early dwarf. Double yay!
Aldy
[-- Attachment #2: curr --]
[-- Type: text/plain, Size: 1289 bytes --]
commit 81de7d658e94160426b38e6c43c09a484fb530ba
Author: Aldy Hernandez <aldyh@redhat.com>
Date: Fri Oct 24 18:00:49 2014 -0600
* dwarf2out.c (declare_in_namespace): Only emit external
declarations in the local scope once.
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index a87f9c0..3bce20f 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -20476,6 +20476,26 @@ declare_in_namespace (tree thing, dw_die_ref context_die)
if (debug_info_level <= DINFO_LEVEL_TERSE)
return context_die;
+ /* External declarations in the local scope only need to be emitted
+ once, not once in the namespace and once in the scope.
+
+ This avoids declaring the `extern' below in the
+ namespace DIE as well as in the innermost scope:
+
+ namespace S
+ {
+ int i=5;
+ int foo()
+ {
+ int i=8;
+ extern int i;
+ return i;
+ }
+ }
+ */
+ if (DECL_P (thing) && DECL_EXTERNAL (thing) && local_scope_p (context_die))
+ return context_die;
+
/* If this decl is from an inlined function, then don't try to emit it in its
namespace, as we will get confused. It would have already been emitted
when the abstract instance of the inline function was emitted anyways. */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch] only emit one DIE for external declarations in the local scope
2014-10-25 1:41 [patch] only emit one DIE for external declarations in the local scope Aldy Hernandez
@ 2014-10-27 0:49 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2014-10-27 0:49 UTC (permalink / raw)
To: Aldy Hernandez, gcc-patches
OK.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-10-26 22:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-25 1:41 [patch] only emit one DIE for external declarations in the local scope Aldy Hernandez
2014-10-27 0:49 ` Jason Merrill
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).