From patchwork Mon Jun 3 22:23:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 248437 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 5A0012C0099 for ; Tue, 4 Jun 2013 08:23:10 +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=SdCYCLvqp1hJ8ah1JDW3Oc7f5j/yog0LtCKt/6uc0nSI72 8D8ugwkCs3oMomKXCwVnsZG9MJ82dwKbjTLpbBYKgYADdRd77P6PwSsPefWs4fmO MGRmm2JdwoFLKzLA5h+N9Hhk7vGhaCR7BzXzOVQxk0N9NuRg5FQcGyZ/2Wg80= 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=qoC58VB9GIeZLp4CN16xgVsu0YI=; b=ht/HVda9Pa2Qeaz/q8ET 7+qdy64NENRoX0gtyPo9XyCrY9ryGfCG9/CQCfjq8XqovMfR/cQPilkk3Dv8Aroa uXWwfbS3ebQe68doS7K/fpCkjz68rbTCSQxii/IbGwpjtjpo/Sf+mZ3zR5BDOPcJ c8xRg7UCx/t4G/6xJKstdto= Received: (qmail 11272 invoked by alias); 3 Jun 2013 22:23:04 -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 11261 invoked by uid 89); 3 Jun 2013 22:23:03 -0000 X-Spam-SWARE-Status: No, score=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 03 Jun 2013 22:23:03 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r53MN1YQ028975 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 3 Jun 2013 18:23:01 -0400 Received: from [10.3.113.130] (ovpn-113-130.phx2.redhat.com [10.3.113.130]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r53MN1Mt003635 for ; Mon, 3 Jun 2013 18:23:01 -0400 Message-ID: <51AD1745.4030201@redhat.com> Date: Mon, 03 Jun 2013 18:23:01 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:23.0) Gecko/20100101 Thunderbird/23.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH to avoid false positives with -Wabi-tag X-Virus-Found: No It occurred to me that -Wabi-tag would probably warn about a template instantiated with a class that has an ABI tag, and indeed it does. This is unnecessary; since the template argument is part of the signature of the instantiation, we don't need to worry about the tag being hidden when the type is used as a base or member. Tested x86_64-pc-linux-gnu, applying to trunk. commit fdeabae097d4140dd56345ee9ca81fb9d6df15b9 Author: Jason Merrill Date: Fri May 31 22:42:48 2013 -0400 * class.c (mark_type_abi_tags): New. (check_abi_tags): Use it. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 64918c6..286164d 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1354,39 +1354,55 @@ find_abi_tags_r (tree *tp, int */*walk_subtrees*/, void *data) return NULL_TREE; } +/* Set IDENTIFIER_MARKED on all the ABI tags on T and its (transitively + complete) template arguments. */ + +static void +mark_type_abi_tags (tree t, bool val) +{ + tree attributes = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (t)); + if (attributes) + { + for (tree list = TREE_VALUE (attributes); list; + list = TREE_CHAIN (list)) + { + tree tag = TREE_VALUE (list); + tree id = get_identifier (TREE_STRING_POINTER (tag)); + IDENTIFIER_MARKED (id) = val; + } + } + + /* Also mark ABI tags from template arguments. */ + if (CLASSTYPE_TEMPLATE_INFO (t)) + { + tree args = CLASSTYPE_TI_ARGS (t); + for (int i = 0; i < TMPL_ARGS_DEPTH (args); ++i) + { + tree level = TMPL_ARGS_LEVEL (args, i+1); + for (int j = 0; j < TREE_VEC_LENGTH (level); ++j) + { + tree arg = TREE_VEC_ELT (level, j); + if (CLASS_TYPE_P (arg)) + mark_type_abi_tags (arg, val); + } + } + } +} + /* Check that class T has all the abi tags that subobject SUBOB has, or warn if not. */ static void check_abi_tags (tree t, tree subob) { - tree attributes = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (t)); - if (attributes) - { - for (tree list = TREE_VALUE (attributes); list; - list = TREE_CHAIN (list)) - { - tree tag = TREE_VALUE (list); - tree id = get_identifier (TREE_STRING_POINTER (tag)); - IDENTIFIER_MARKED (id) = true; - } - } + mark_type_abi_tags (t, true); tree subtype = TYPE_P (subob) ? subob : TREE_TYPE (subob); struct abi_tag_data data = { t, subob }; cp_walk_tree_without_duplicates (&subtype, find_abi_tags_r, &data); - if (attributes) - { - for (tree list = TREE_VALUE (attributes); list; - list = TREE_CHAIN (list)) - { - tree tag = TREE_VALUE (list); - tree id = get_identifier (TREE_STRING_POINTER (tag)); - IDENTIFIER_MARKED (id) = false; - } - } + mark_type_abi_tags (t, false); } /* Run through the base classes of T, updating CANT_HAVE_CONST_CTOR_P, diff --git a/gcc/testsuite/g++.dg/abi/abi-tag5.C b/gcc/testsuite/g++.dg/abi/abi-tag5.C new file mode 100644 index 0000000..de55802 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/abi-tag5.C @@ -0,0 +1,6 @@ +// { dg-options -Wabi-tag } + +struct __attribute__ ((abi_tag ("foo"))) A { }; +template struct B: T { }; + +B b;