From patchwork Wed Sep 10 17:28:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 387909 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 795E0140131 for ; Thu, 11 Sep 2014 03:28:35 +1000 (EST) 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=MXWb81kSR5wR55eYSEWtVMdYGEBlS9JBblxKcxekbebuO1 F7xHhqypgpCMaGWo+euNv6tdU4o5M1Zj/7CLuvQrKYdEKHgHMx57R3b4PTaSeR/G vdkAeKz/4yl8pydjmuQmFwiLat4kDTPITVhoh8VpdIfNDoKFHWPythX0yk24E= 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=j2cmfg1rnps5bLDQcRQmsSuVhMg=; b=QwKELmhSD0rWTdd7uc+G t6azupm8I4/fU7pFaqsux8q7EmiurwBEXz/VlQwrKaM3H30iir1xfXpYtPgX7Lov Cm7qA7yMiujKEcfsgYBjh1bO4ODS4d8abCiNz+N7KGkGS40SWOjZvapSPsB92US0 ruiggcMakSHmI+JD7HWHjbE= Received: (qmail 19925 invoked by alias); 10 Sep 2014 17:28:28 -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 19914 invoked by uid 89); 10 Sep 2014 17:28:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.0 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; Wed, 10 Sep 2014 17:28:27 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8AHSPZW024028 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 10 Sep 2014 13:28:25 -0400 Received: from [10.10.116.27] ([10.10.116.27]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8AHSOqH026469; Wed, 10 Sep 2014 13:28:24 -0400 Message-ID: <54108A35.1090907@redhat.com> Date: Wed, 10 Sep 2014 13:28:21 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: gcc-patches List , John David Anglin Subject: Another C++ PATCH for c++/61659 (DECL_COMDAT and devirt) After * decl.c (maybe_commonize_var): Don't use DECL_COMDAT to trigger comdat_linkage. targets without weak symbol support started getting link errors bootstrapping GCC. This ought to fix that. Tested x86_64-pc-linux-gnu, applying to trunk. commit e3859ec10649526a24b439301db79a34d7b90ba3 Author: Jason Merrill Date: Tue Sep 9 12:21:03 2014 -0400 PR c++/61659 * decl.c (grokfndecl): Don't set DECL_COMDAT on static inlines. (duplicate_decls, start_decl): Likewise. * pt.c (check_explicit_specialization): Likewise. (push_template_decl_real): Or static templates. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index d8fb35e..6e195bb 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -2215,7 +2215,8 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) olddecl); SET_DECL_TEMPLATE_SPECIALIZATION (olddecl); - DECL_COMDAT (newdecl) = DECL_DECLARED_INLINE_P (newdecl); + DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl) + && DECL_DECLARED_INLINE_P (newdecl)); /* Don't propagate visibility from the template to the specialization here. We'll do that in determine_visibility if @@ -4718,7 +4719,8 @@ start_decl (const cp_declarator *declarator, { SET_DECL_TEMPLATE_SPECIALIZATION (decl); if (TREE_CODE (decl) == FUNCTION_DECL) - DECL_COMDAT (decl) = DECL_DECLARED_INLINE_P (decl); + DECL_COMDAT (decl) = (TREE_PUBLIC (decl) + && DECL_DECLARED_INLINE_P (decl)); else DECL_COMDAT (decl) = false; @@ -7699,7 +7701,8 @@ grokfndecl (tree ctype, if (inlinep) { DECL_DECLARED_INLINE_P (decl) = 1; - DECL_COMDAT (decl) = 1; + if (publicp) + DECL_COMDAT (decl) = 1; } if (inlinep & 2) DECL_DECLARED_CONSTEXPR_P (decl) = true; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 44569e2..3c93178 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2813,7 +2813,8 @@ check_explicit_specialization (tree declarator, SET_DECL_IMPLICIT_INSTANTIATION (decl); else if (TREE_CODE (decl) == FUNCTION_DECL) /* A specialization is not necessarily COMDAT. */ - DECL_COMDAT (decl) = DECL_DECLARED_INLINE_P (decl); + DECL_COMDAT (decl) = (TREE_PUBLIC (decl) + && DECL_DECLARED_INLINE_P (decl)); else if (TREE_CODE (decl) == VAR_DECL) DECL_COMDAT (decl) = false; @@ -5059,6 +5060,7 @@ template arguments to %qD do not match original template %qD", if (flag_implicit_templates && !is_friend + && TREE_PUBLIC (decl) && VAR_OR_FUNCTION_DECL_P (decl)) /* Set DECL_COMDAT on template instantiations; if we force them to be emitted by explicit instantiation or -frepo, diff --git a/gcc/testsuite/g++.dg/abi/no-weak1.C b/gcc/testsuite/g++.dg/abi/no-weak1.C new file mode 100644 index 0000000..663643f --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/no-weak1.C @@ -0,0 +1,21 @@ +// { dg-options "-fno-weak" } +// { dg-final { scan-assembler "local\[ \t\]*_ZZL1fvE1i" { target x86_64-*-*gnu } } } +// { dg-final { scan-assembler "local\[ \t\]*_ZZ1gIiEvvE1i" { target x86_64-*-*gnu } } } + +static inline void f() +{ + static int i; + ++i; +}; + +template static void g() +{ + static int i; + ++i; +} + +int main() +{ + f(); + g(); +}