From patchwork Thu Jun 25 03:12:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 488274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C2B6B1402C3 for ; Thu, 25 Jun 2015 13:12:48 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=UCnIf26v; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=pTbt7Wzcmx9iRTg+2rXv5B6BmcEK5a6UqLjaj4MxfppJ4Q qVadJFc74hQPORbMNSf9XLfHKBIPCkThwDsHYm1ullp9NTE1z1qCd5FdxCf3jR/3 3V5ZUyTwEUOCDh+GnKagS47MPLowyPC5SiBj+qmc90iGxQ4k7fckslAlEpJJA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=HUZgRtshbg3jyCZAqaUAFTIlMvI=; b=UCnIf26vQskJ+M+QfOoe vQnzWv+OSAvtsftmdpKRaDtj2KpBpNY+jjkJsK/tO4v2FdvpIwBfEf8cy6RmERCc OnmZLmeLuVSkbgnb4wefWzboM/i9Q12CXR5DDiMQ0Y36sBUCFg+NeuG8D6R7DMMN tQcZnOrsAXJgQmf/p7BofmM= Received: (qmail 10427 invoked by alias); 25 Jun 2015 03:12:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 10398 invoked by uid 89); 25 Jun 2015 03:12:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-6.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 25 Jun 2015 03:12:38 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 031EFB82BB for ; Thu, 25 Jun 2015 03:12:36 +0000 (UTC) Received: from reynosa.quesejoda.com (vpn-63-154.rdu2.redhat.com [10.10.63.154]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5P3CZua001143; Wed, 24 Jun 2015 23:12:36 -0400 Message-ID: <558B71A3.3080004@redhat.com> Date: Wed, 24 Jun 2015 20:12:35 -0700 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: gcc-patches , jason merrill Subject: [patch] PR debug/66653: avoid late_global_decl on decl_type_context()s 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 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? commit 302f9976c53aa09e431bd54f37dbfeaa2c6b2acc Author: Aldy Hernandez 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 class A +{ + static __thread T a; +};