summaryrefslogtreecommitdiff
path: root/gcc/ipa-devirt.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2019-12-02 12:18:31 +0100
committerMartin Liska <marxin@gcc.gnu.org>2019-12-02 11:18:31 +0000
commit74fee04253a5007213634150b4505cd6fcab9910 (patch)
tree1e48621652810407242276de2e0a47c7126a3e6a /gcc/ipa-devirt.c
parentf87c23751ab207ee44c2956a444c2c80a797d1fe (diff)
Refactor IPA devirt a bit.
2019-12-02 Martin Liska <mliska@suse.cz> * ipa-devirt.c (warn_types_mismatch): Use get_odr_name_for_type function. (debug_tree_odr_name): New. * ipa-utils.h (get_odr_name_for_type): New. 2019-12-02 Martin Liska <mliska@suse.cz> * g++.dg/lto/odr-7_0.C: New test. * g++.dg/lto/odr-7_1.C: New test. From-SVN: r278898
Diffstat (limited to 'gcc/ipa-devirt.c')
-rw-r--r--gcc/ipa-devirt.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index a884a465a5d..1017b2a5c7c 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -1036,20 +1036,13 @@ warn_types_mismatch (tree t1, tree t2, location_t loc1, location_t loc2)
/* If types have mangled ODR names and they are different, it is most
informative to output those.
This also covers types defined in different namespaces. */
- if (TYPE_NAME (mt1) && TYPE_NAME (mt2)
- && TREE_CODE (TYPE_NAME (mt1)) == TYPE_DECL
- && TREE_CODE (TYPE_NAME (mt2)) == TYPE_DECL
- && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (mt1))
- && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (mt2))
- && DECL_ASSEMBLER_NAME (TYPE_NAME (mt1))
- != DECL_ASSEMBLER_NAME (TYPE_NAME (mt2)))
- {
- char *name1 = xstrdup (cplus_demangle
- (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (TYPE_NAME (mt1))),
- DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES));
- char *name2 = cplus_demangle
- (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (TYPE_NAME (mt2))),
- DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES);
+ const char *odr1 = get_odr_name_for_type (mt1);
+ const char *odr2 = get_odr_name_for_type (mt2);
+ if (odr1 != NULL && odr2 != NULL && odr1 != odr2)
+ {
+ const int opts = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES;
+ char *name1 = xstrdup (cplus_demangle (odr1, opts));
+ char *name2 = xstrdup (cplus_demangle (odr2, opts));
if (name1 && name2 && strcmp (name1, name2))
{
inform (loc_t1,
@@ -3989,4 +3982,20 @@ make_pass_ipa_devirt (gcc::context *ctxt)
return new pass_ipa_devirt (ctxt);
}
+/* Print ODR name of a TYPE if available.
+ Use demangler when option DEMANGLE is used. */
+
+DEBUG_FUNCTION void
+debug_tree_odr_name (tree type, bool demangle)
+{
+ const char *odr = get_odr_name_for_type (type);
+ if (demangle)
+ {
+ const int opts = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES;
+ odr = cplus_demangle (odr, opts);
+ }
+
+ fprintf (stderr, "%s\n", odr);
+}
+
#include "gt-ipa-devirt.h"