public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] PR debug/66653: avoid late_global_decl on decl_type_context()s
@ 2015-06-25  3:19 Aldy Hernandez
  2015-06-25  9:49 ` Richard Biener
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Aldy Hernandez @ 2015-06-25  3:19 UTC (permalink / raw)
  To: gcc-patches, jason merrill

[-- Attachment #1: Type: text/plain, Size: 1658 bytes --]

The problem here is that we are trying to call 
dwarf2out_late_global_decl() on a static variable in a template which 
has a type of TEMPLATE_TYPE_PARM:

template <typename T> class A
{
   static __thread T a;
};

We are calling late_global_decl because we are about to remove the 
unused static from the symbol table:

	  /* See if the debugger can use anything before the DECL
	     passes away.  Perhaps it can notice a DECL that is now a
	     constant and can tag the early DIE with an appropriate
	     attribute.

	     Otherwise, this is the last chance the debug_hooks have
	     at looking at optimized away DECLs, since
	     late_global_decl will subsequently be called from the
	     contents of the now pruned symbol table.  */
	  if (!decl_function_context (node->decl))
	    (*debug_hooks->late_global_decl) (node->decl);

Since gen_type_die_with_usage() cannot handle TEMPLATE_TYPE_PARMs we ICE.

I think we need to avoid calling late_global_decl on DECL's for which 
decl_type_context() is true, similarly to what we do for the call to 
early_global_decl in rest_of_decl_compilation:

       && !decl_function_context (decl)
       && !current_function_decl
       && DECL_SOURCE_LOCATION (decl) != BUILTINS_LOCATION
       && !decl_type_context (decl))
     (*debug_hooks->early_global_decl) (decl);

Presumably the old code did not run into this problem because the 
TEMPLATE_TYPE_PARAMs had been lowered by the time dwarf2out_decl was 
called, but here we are calling late_global_decl relatively early.

The attached patch fixes the problem.

Tested with --enable-languages=all.  Ada had other issues, so I skipped it.

OK for mainline?

[-- Attachment #2: curr --]
[-- Type: text/plain, Size: 1173 bytes --]

commit 302f9976c53aa09e431bd54f37dbfeaa2c6b2acc
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Jun 24 20:04:09 2015 -0700

    	PR debug/66653
    	* cgraphunit.c (analyze_functions): Do not call
    	debug_hooks->late_global_decl when decl_type_context.

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 066a155..d2974ad 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -1149,7 +1149,8 @@ analyze_functions (bool first_time)
 	     at looking at optimized away DECLs, since
 	     late_global_decl will subsequently be called from the
 	     contents of the now pruned symbol table.  */
-	  if (!decl_function_context (node->decl))
+	  if (!decl_function_context (node->decl)
+	      && !decl_type_context (node->decl))
 	    (*debug_hooks->late_global_decl) (node->decl);
 
 	  node->remove ();
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/pr66653.C b/gcc/testsuite/g++.dg/debug/dwarf2/pr66653.C
new file mode 100644
index 0000000..bcaaf88
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/pr66653.C
@@ -0,0 +1,8 @@
+// PR debug/54508
+// { dg-do compile }
+// { dg-options "-g" }
+
+template <typename T> class A
+{
+  static __thread T a;
+};

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-07-01  7:39 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-25  3:19 [patch] PR debug/66653: avoid late_global_decl on decl_type_context()s Aldy Hernandez
2015-06-25  9:49 ` Richard Biener
2015-06-25 15:08   ` Aldy Hernandez
2015-06-25 13:56 ` Eric Botcazou
2015-06-25 14:57   ` Aldy Hernandez
2015-06-25 20:57     ` Eric Botcazou
2015-06-25 17:02 ` Jason Merrill
2015-06-26  9:40   ` Richard Biener
2015-06-26 22:04     ` Jason Merrill
2015-06-29  9:14       ` Richard Biener
2015-06-29 22:35         ` Jason Merrill
2015-06-30 14:43           ` Jason Merrill
2015-07-01  7:39             ` Richard Biener

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).