aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2015-05-08 23:28:52 -0400
committerAldy Hernandez <aldyh@gcc.gnu.org>2015-05-09 03:28:52 +0000
commit613aba20e554f92bc7008dabb1b0c42a6207da33 (patch)
tree7caf557f25ae5b4702351dd8b0cff09dda864d87 /gcc
parent09c5f835e7ca90b344a6471acbe360fc33b77fa7 (diff)
downloadgcc-613aba20e554f92bc7008dabb1b0c42a6207da33.zip
gcc-613aba20e554f92bc7008dabb1b0c42a6207da33.tar.gz
gcc-613aba20e554f92bc7008dabb1b0c42a6207da33.tar.bz2
decl2.c (mangling_aliases): New variable.
* decl2.c (mangling_aliases): New variable. (note_mangling_alias, generate_mangling_aliases): New. (cp_write_global_declarations): Call generate_mangling_aliases. (generate_mangling_alias): Split out from... * mangle.c (mangle_decl): ...here. * cp-tree.h: Declare note_mangling_alias. From-SVN: r222934
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/decl2.c66
-rw-r--r--gcc/cp/mangle.c25
4 files changed, 77 insertions, 24 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1fbf765..0910549 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+2015-05-08 Jason Merrill <jason@redhat.com>
+
+ * decl2.c (mangling_aliases): New variable.
+ (note_mangling_alias, generate_mangling_aliases): New.
+ (cp_write_global_declarations): Call generate_mangling_aliases.
+ (generate_mangling_alias): Split out from...
+ * mangle.c (mangle_decl): ...here.
+ * cp-tree.h: Declare note_mangling_alias.
+
2015-05-08 Aldy Hernandez <aldyh@redhat.com>
* decl2.c (collect_candidates_for_java_method_aliases): Remove.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index e0fbf5e..4136d98 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5447,6 +5447,7 @@ extern tree finish_case_label (location_t, tree, tree);
extern tree cxx_maybe_build_cleanup (tree, tsubst_flags_t);
/* in decl2.c */
+extern void note_mangling_alias (tree, tree);
extern bool check_java_method (tree);
extern tree build_memfn_type (tree, tree, cp_cv_quals, cp_ref_qualifier);
extern tree build_pointer_ptrmemfn_type (tree);
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index dcc5e1f..6101301 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -118,6 +118,10 @@ static GTY(()) vec<tree, va_gc> *deferred_fns;
sure are defined. */
static GTY(()) vec<tree, va_gc> *no_linkage_decls;
+/* A vector of alternating decls and identifiers, where the latter
+ is to be an alias for the former if the former is defined. */
+static GTY(()) vec<tree, va_gc> *mangling_aliases;
+
/* Nonzero if we're done parsing and into end-of-file activities. */
int at_eof;
@@ -4287,6 +4291,66 @@ handle_tls_init (void)
expand_or_defer_fn (finish_function (0));
}
+/* We're at the end of compilation, so generate any mangling aliases that
+ we've been saving up, if DECL is going to be output and ID2 isn't
+ already taken by another declaration. */
+
+static void
+generate_mangling_alias (tree decl, tree id2)
+{
+ /* If there's a declaration already using this mangled name,
+ don't create a compatibility alias that conflicts. */
+ if (IDENTIFIER_GLOBAL_VALUE (id2))
+ return;
+
+ struct cgraph_node *n = NULL;
+ if (TREE_CODE (decl) == FUNCTION_DECL
+ && !(n = cgraph_node::get (decl)))
+ /* Don't create an alias to an unreferenced function. */
+ return;
+
+ tree alias = make_alias_for (decl, id2);
+ SET_IDENTIFIER_GLOBAL_VALUE (id2, alias);
+ DECL_IGNORED_P (alias) = 1;
+ TREE_PUBLIC (alias) = TREE_PUBLIC (decl);
+ DECL_VISIBILITY (alias) = DECL_VISIBILITY (decl);
+ if (vague_linkage_p (decl))
+ DECL_WEAK (alias) = 1;
+ if (TREE_CODE (decl) == FUNCTION_DECL)
+ n->create_same_body_alias (alias, decl);
+ else
+ varpool_node::create_extra_name_alias (alias, decl);
+}
+
+/* Note that we might want to emit an alias with the symbol ID2 for DECL at
+ the end of translation, for compatibility across bugs in the mangling
+ implementation. */
+
+void
+note_mangling_alias (tree decl, tree id2)
+{
+#ifdef ASM_OUTPUT_DEF
+ if (at_eof)
+ generate_mangling_alias (decl, id2);
+ else
+ {
+ vec_safe_push (mangling_aliases, decl);
+ vec_safe_push (mangling_aliases, id2);
+ }
+#endif
+}
+
+static void
+generate_mangling_aliases ()
+{
+ while (!vec_safe_is_empty (mangling_aliases))
+ {
+ tree id2 = mangling_aliases->pop();
+ tree decl = mangling_aliases->pop();
+ generate_mangling_alias (decl, id2);
+ }
+}
+
/* The entire file is now complete. If requested, dump everything
to a file. */
@@ -4647,6 +4711,8 @@ cp_write_global_declarations (void)
}
while (reconsider);
+ generate_mangling_aliases ();
+
/* All used inline functions must have a definition at this point. */
FOR_EACH_VEC_SAFE_ELT (deferred_fns, i, decl)
{
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index b0f72d1..647ec70 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -3554,30 +3554,7 @@ mangle_decl (const tree decl)
flag_abi_compat_version, id2);
}
-#ifdef ASM_OUTPUT_DEF
- /* If there's a declaration already using this mangled name,
- don't create a compatibility alias that conflicts. */
- if (IDENTIFIER_GLOBAL_VALUE (id2))
- return;
-
- struct cgraph_node *n = NULL;
- if (TREE_CODE (decl) == FUNCTION_DECL
- && !(n = cgraph_node::get (decl)))
- /* Don't create an alias to an unreferenced function. */
- return;
-
- tree alias = make_alias_for (decl, id2);
- SET_IDENTIFIER_GLOBAL_VALUE (id2, alias);
- DECL_IGNORED_P (alias) = 1;
- TREE_PUBLIC (alias) = TREE_PUBLIC (decl);
- DECL_VISIBILITY (alias) = DECL_VISIBILITY (decl);
- if (vague_linkage_p (decl))
- DECL_WEAK (alias) = 1;
- if (TREE_CODE (decl) == FUNCTION_DECL)
- n->create_same_body_alias (alias, decl);
- else
- varpool_node::create_extra_name_alias (alias, decl);
-#endif
+ note_mangling_alias (decl, id2);
}
}