From patchwork Thu Jan 7 16:47:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1423394 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=GwkZ1xmP; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DBXGV5TVqz9s1l for ; Fri, 8 Jan 2021 03:47:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F807395CC03; Thu, 7 Jan 2021 16:47:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F807395CC03 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1610038062; bh=OiQea1AN/JnX/1QXieVq4C35J/+FIuQkDra2oiy+Drk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=GwkZ1xmPXz7+SDAWgaMrhuiA5ylT1ytK7ApSYBVQyKhe/ny+DJmuzWBlT7MB5BIqL gdT0MRN1pWx0VaW0uB7fT4iKwPY6KL2Hyj2+Tf3G+Wfm2NeI6vNEh3r5IwexaEwAvl vLjVQpUfQv/hgIDh1eQE8tDiX+o6kEmGF0g4dPYY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 4D6E0386EC62 for ; Thu, 7 Jan 2021 16:47:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4D6E0386EC62 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-130-lzjTLzx6P2qGK7ygFPfc9Q-1; Thu, 07 Jan 2021 11:47:38 -0500 X-MC-Unique: lzjTLzx6P2qGK7ygFPfc9Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 386231936B60 for ; Thu, 7 Jan 2021 16:47:37 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-11.ams2.redhat.com [10.36.112.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC16A6268E; Thu, 7 Jan 2021 16:47:36 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 107GlONK3255428 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 7 Jan 2021 17:47:24 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 107GlI8X3255427; Thu, 7 Jan 2021 17:47:18 +0100 Date: Thu, 7 Jan 2021 17:47:18 +0100 To: Jason Merrill Subject: [PATCH] c++, abi: Fix abi_tag attribute handling [PR98481] Message-ID: <20210107164718.GP725145@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! In GCC10 cp_walk_subtrees has been changed to walk template arguments. As the following testcase, that changed the mangling of some functions. I believe the previous behavior that find_abi_tags_r doesn't recurse into template args has been the correct one, but setting *walk_subtrees = 0 for the types and handling the types subtree walking manually in find_abi_tags_r looks too hard, there are a lot of subtrees and details what should and shouldn't be walked, both in tree.c (walk_type_fields there, which is static) and in cp_walk_subtrees itself. The following patch abuses the fact that *walk_subtrees is an int to tell cp_walk_subtrees it shouldn't walk the template args. Another option would be to have two separate cp_walk_subtrees-like callbacks, one that wouldn't walk into template args and the other that would and then would tail call the other one, and cp_walk_tree_without_duplicates but call walk_tree_1 directly or use some other macro. Now that I look at it, likely mark_abi_tags_r should behave the same way. Bootstrapped/regtested on x86_64-linux and i686-linux. 2021-01-07 Jakub Jelinek PR c++/98481 * tree.c (cp_walk_subtrees): Don't walk template args if *walk_subtrees_p is 2. * class.c (find_abi_tags_r): Set *walk_subtrees to 2 instead of 1 for types. * g++.dg/abi/abi-tag24.C: New test. Jakub --- gcc/cp/tree.c.jj 2021-01-04 10:25:49.102117545 +0100 +++ gcc/cp/tree.c 2021-01-07 12:43:17.674974823 +0100 @@ -5147,8 +5147,9 @@ cp_walk_subtrees (tree *tp, int *walk_su if (TYPE_P (*tp)) { /* Walk into template args without looking through typedefs. */ - if (tree ti = TYPE_TEMPLATE_INFO_MAYBE_ALIAS (*tp)) - WALK_SUBTREE (TI_ARGS (ti)); + if (*walk_subtrees_p != 2) + if (tree ti = TYPE_TEMPLATE_INFO_MAYBE_ALIAS (*tp)) + WALK_SUBTREE (TI_ARGS (ti)); /* Don't look through typedefs; walk_tree_fns that want to look through typedefs (like min_vis_r) need to do that themselves. */ if (typedef_variant_p (*tp)) --- gcc/cp/class.c.jj 2021-01-04 10:25:48.933119459 +0100 +++ gcc/cp/class.c 2021-01-07 12:50:51.723881933 +0100 @@ -1508,7 +1508,12 @@ static tree find_abi_tags_r (tree *tp, int *walk_subtrees, void *data) { if (!OVERLOAD_TYPE_P (*tp)) - return NULL_TREE; + { + if (TYPE_P (*tp) && *walk_subtrees == 1) + /* Tell cp_walk_subtrees not to walk into template args. */ + *walk_subtrees = 2; + return NULL_TREE; + } /* walk_tree shouldn't be walking into any subtrees of a RECORD_TYPE anyway, but let's make sure of it. */ --- gcc/testsuite/g++.dg/abi/abi-tag24.C.jj 2021-01-07 12:58:12.128942173 +0100 +++ gcc/testsuite/g++.dg/abi/abi-tag24.C 2021-01-07 12:58:47.995539911 +0100 @@ -0,0 +1,17 @@ +// PR c++/98481 +// { dg-do compile { target c++11 } } +inline namespace N __attribute ((__abi_tag__ ("myabi"))) +{ + struct A {}; +} +template +struct B { typedef int size_type; }; +struct S1 { B::size_type foo () const { return 1; } }; +struct S2 { B::size_type foo () const; }; +int S2::foo () const { return 2; } +int (S1::*f1) () const = &S1::foo; +int (S2::*f2) () const = &S2::foo; + +// { dg-final { scan-assembler "_ZNK2S13fooEv" } } +// { dg-final { scan-assembler "_ZNK2S23fooEv" } } +// { dg-final { scan-assembler-not "_ZNK2S13fooB5myabiEv" } }