public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-6592] c++, abi: Fix abi_tag attribute handling [PR98481]
@ 2021-01-11 16:15 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-01-11 16:15 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:3dd0d3ee1d2a988e7f3a3e8f009fcf328f16d2ed
commit r11-6592-g3dd0d3ee1d2a988e7f3a3e8f009fcf328f16d2ed
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Jan 7 17:47:18 2021 +0100
c++, abi: Fix abi_tag attribute handling [PR98481]
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.
Co-authored-by: Jason Merrill <jason@redhat.com>
gcc/cp/ChangeLog:
PR c++/98481
* class.c (find_abi_tags_r): Set *walk_subtrees to 2 instead of 1
for types.
(mark_abi_tags_r): Likewise.
* decl2.c (min_vis_r): Likewise.
* tree.c (cp_walk_subtrees): If *walk_subtrees_p is 2, look through
typedefs.
gcc/testsuite/ChangeLog:
PR c++/98481
* g++.dg/abi/abi-tag24.C: New test.
Diff:
---
gcc/cp/class.c | 8 ++++++++
gcc/cp/decl2.c | 7 ++++---
gcc/cp/tree.c | 22 ++++++++++++++++------
gcc/testsuite/g++.dg/abi/abi-tag24.C | 17 +++++++++++++++++
4 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index c41ac7deefe..00c0dba0a55 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -1507,6 +1507,10 @@ mark_or_check_tags (tree t, tree *tp, abi_tag_data *p, bool val)
static tree
find_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
{
+ if (TYPE_P (*tp) && *walk_subtrees == 1)
+ /* Tell cp_walk_subtrees to look though typedefs. */
+ *walk_subtrees = 2;
+
if (!OVERLOAD_TYPE_P (*tp))
return NULL_TREE;
@@ -1527,6 +1531,10 @@ find_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
static tree
mark_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
{
+ if (TYPE_P (*tp) && *walk_subtrees == 1)
+ /* Tell cp_walk_subtrees to look though typedefs. */
+ *walk_subtrees = 2;
+
if (!OVERLOAD_TYPE_P (*tp))
return NULL_TREE;
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index b10671091b5..b087753cfba 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -2358,9 +2358,6 @@ min_vis_r (tree *tp, int *walk_subtrees, void *data)
int this_vis = VISIBILITY_DEFAULT;
if (! TYPE_P (*tp))
*walk_subtrees = 0;
- else if (typedef_variant_p (*tp))
- /* Look through typedefs despite cp_walk_subtrees. */
- this_vis = type_visibility (DECL_ORIGINAL_TYPE (TYPE_NAME (*tp)));
else if (OVERLOAD_TYPE_P (*tp)
&& !TREE_PUBLIC (TYPE_MAIN_DECL (*tp)))
{
@@ -2379,6 +2376,10 @@ min_vis_r (tree *tp, int *walk_subtrees, void *data)
if (this_vis > *vis_p)
*vis_p = this_vis;
+ /* Tell cp_walk_subtrees to look through typedefs. */
+ if (*walk_subtrees == 1)
+ *walk_subtrees = 2;
+
return NULL;
}
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 82027cc9abf..c536eb581a7 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -5146,16 +5146,26 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
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));
- /* 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))
+ /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
+ the argument, so don't look through typedefs, but do walk into
+ template arguments for alias templates (and non-typedefed classes).
+
+ If *WALK_SUBTREES_P > 1, we're interested in type identity or
+ equivalence, so look through typedefs, ignoring template arguments for
+ alias templates, and walk into template args of classes.
+
+ See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
+ when that's the behavior the walk_tree_fn wants. */
+ if (*walk_subtrees_p == 1 && typedef_variant_p (*tp))
{
+ if (tree ti = TYPE_ALIAS_TEMPLATE_INFO (*tp))
+ WALK_SUBTREE (TI_ARGS (ti));
*walk_subtrees_p = 0;
return NULL_TREE;
}
+
+ if (tree ti = TYPE_TEMPLATE_INFO (*tp))
+ WALK_SUBTREE (TI_ARGS (ti));
}
/* Not one of the easy cases. We must explicitly go through the
diff --git a/gcc/testsuite/g++.dg/abi/abi-tag24.C b/gcc/testsuite/g++.dg/abi/abi-tag24.C
new file mode 100644
index 00000000000..c758544b090
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/abi-tag24.C
@@ -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" } }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-11 16:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 16:15 [gcc r11-6592] c++, abi: Fix abi_tag attribute handling [PR98481] Jason Merrill
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).