public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] c++, abi: Fix abi_tag attribute handling [PR98481]
Date: Thu, 7 Jan 2021 17:47:18 +0100	[thread overview]
Message-ID: <20210107164718.GP725145@tucnak> (raw)

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  <jakub@redhat.com>

	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.

--- 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 <typename T>
+struct B { typedef int size_type; };
+struct S1 { B<A>::size_type foo () const { return 1; } };
+struct S2 { B<A>::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" } }

	Jakub


             reply	other threads:[~2021-01-07 16:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-07 16:47 Jakub Jelinek [this message]
2021-01-08 19:22 ` Jason Merrill
2021-01-08 19:29   ` Jakub Jelinek
2021-04-01  4:52     ` Jason Merrill
2021-04-01  5:47       ` Jakub Jelinek
2021-04-01  7:56         ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210107164718.GP725145@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).