From patchwork Sun Jan 31 11:49:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 576177 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 2239D140C2D for ; Sun, 31 Jan 2016 22:49:25 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=b06z9fPV; 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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=G0r1A5/v0zGmfqBFO1+TYoXoDUvhVNbTT3Ut8kuznYHRx1IPG5 p5X/j0Z7NFkR7XJ6KiQZQhewsg7sQZ9tfNcGNVPj7nVKaMUgHfWRhY1BOEwd2EXo FvLTrSocYvhBAe3Q1T9OxWD9alvnFN3PsdWA3RM9MQFxUeAjWjH1dCIxM= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=QBsL3mh6EI/cuWAJe227iNiNGfA=; b=b06z9fPV/3AODtzWwd3R oKmX+nF3s5KHeTXXSQV9qwIs3rW1smLCSL4KlnqCFAsn/A3PrIlvGq7F6QCMZ0ky LVC0PPAQ6izWz9DBaW7RmbJeTbaBTJAXBfWu6JXc7i+IVN8dqbE7e23f/IcoUoHN rpips/ppmnan8zOBVxKtLbI= Received: (qmail 28969 invoked by alias); 31 Jan 2016 11:49:17 -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 28941 invoked by uid 89); 31 Jan 2016 11:49:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=whereby, TYPE_ATTRIBUTES, type_attributes, tree_cons 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; Sun, 31 Jan 2016 11:49:15 +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 B2B42C0C2344 for ; Sun, 31 Jan 2016 11:49:12 +0000 (UTC) Received: from [10.3.113.55] (ovpn-113-55.phx2.redhat.com [10.3.113.55]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0VBnBr9031684 for ; Sun, 31 Jan 2016 06:49:12 -0500 To: gcc-patches List From: Jason Merrill Subject: C++ PATCHes for abi_tag bugs Message-ID: <56ADF4B7.9010905@redhat.com> Date: Sun, 31 Jan 2016 12:49:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 These patches fix a couple of abi_tag bugs that were reported to me recently. The first is an issue whereby all instantiations of a class template were sharing tags, so instantiating a template with a tagged type argument would apply the tag to another instantiation. Oops. The second is an issue where the multiple-initialization guard for a tagged variable was not itself tagged. Tested x86_64-pc-linux-gnu, applying to trunk. commit 615067ce890764a32a1fc6978ec17b6c1a2f4645 Author: Jason Merrill Date: Fri Jan 29 03:02:31 2016 -0500 * mangle.c (maybe_check_abi_tags): New. (write_guarded_var_name): Call it. (mangle_ref_init_variable): Call check_abi_tags. diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 4f1eea6..2bb7048 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -3931,6 +3931,30 @@ mangle_conv_op_name_for_type (const tree type) return identifier; } +/* Handle ABI backwards compatibility for past bugs where we didn't call + check_abi_tags in places where it's needed: call check_abi_tags and warn if + it makes a difference. */ + +static void +maybe_check_abi_tags (tree t) +{ + tree attr = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (t)); + tree oldtags = NULL_TREE; + if (attr) + oldtags = TREE_VALUE (attr); + + check_abi_tags (t); + + if (!attr) + attr = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (t)); + if (attr && TREE_VALUE (attr) != oldtags + && abi_version_crosses (10)) + warning_at (DECL_SOURCE_LOCATION (t), OPT_Wabi, + "the mangled name of the initialization guard variable for" + "%qD changes between -fabi-version=%d and -fabi-version=%d", + t, flag_abi_version, warn_abi_version); +} + /* Write out the appropriate string for this variable when generating another mangled name based on this one. */ @@ -3943,7 +3967,15 @@ write_guarded_var_name (const tree variable) to the reference, not the temporary. */ write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4); else - write_name (variable, /*ignore_local_scope=*/0); + { + /* Before ABI v10 we were failing to call check_abi_tags here. So if + we're in pre-10 mode, wait until after write_name to call it. */ + if (abi_version_at_least (10)) + maybe_check_abi_tags (variable); + write_name (variable, /*ignore_local_scope=*/0); + if (!abi_version_at_least (10)) + maybe_check_abi_tags (variable); + } } /* Return an identifier for the name of an initialization guard @@ -4007,6 +4039,7 @@ mangle_ref_init_variable (const tree variable) { start_mangling (variable); write_string ("_ZGR"); + check_abi_tags (variable); write_name (variable, /*ignore_local_scope=*/0); /* Avoid name clashes with aggregate initialization of multiple references at once. */ diff --git a/gcc/testsuite/g++.dg/abi/abi-tag16.C b/gcc/testsuite/g++.dg/abi/abi-tag16.C new file mode 100644 index 0000000..d4fa142 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/abi-tag16.C @@ -0,0 +1,19 @@ +// { dg-options -Wabi=9 } +// { dg-final { scan-assembler "_ZGVZN1N1FEvE4NameB5cxx11" } } +namespace std { + __extension__ inline namespace __cxx11 __attribute__((abi_tag("cxx11"))) { + struct String { + String(); + }; + } +} +namespace N { + inline void F() { + { + static std::String Name; // { dg-warning "mangled name" } + } + } + void F2() { + F(); + } +} diff --git a/gcc/testsuite/g++.dg/abi/abi-tag16a.C b/gcc/testsuite/g++.dg/abi/abi-tag16a.C new file mode 100644 index 0000000..b02e856 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/abi-tag16a.C @@ -0,0 +1,19 @@ +// { dg-options "-fabi-version=9 -Wabi" } +// { dg-final { scan-assembler "_ZGVZN1N1FEvE4Name" } } +namespace std { + __extension__ inline namespace __cxx11 __attribute__((abi_tag("cxx11"))) { + struct String { + String(); + }; + } +} +namespace N { + inline void F() { + { + static std::String Name; // { dg-warning "mangled name" } + } + } + void F2() { + F(); + } +}