Commit 74fee042 by Martin Liska Committed by Martin Liska

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
parent f87c2375
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 Richard Biener <rguenther@suse.de> 2019-12-02 Richard Biener <rguenther@suse.de>
PR tree-optimization/92742 PR tree-optimization/92742
...@@ -1036,20 +1036,13 @@ warn_types_mismatch (tree t1, tree t2, location_t loc1, location_t loc2) ...@@ -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 /* If types have mangled ODR names and they are different, it is most
informative to output those. informative to output those.
This also covers types defined in different namespaces. */ This also covers types defined in different namespaces. */
if (TYPE_NAME (mt1) && TYPE_NAME (mt2) const char *odr1 = get_odr_name_for_type (mt1);
&& TREE_CODE (TYPE_NAME (mt1)) == TYPE_DECL const char *odr2 = get_odr_name_for_type (mt2);
&& TREE_CODE (TYPE_NAME (mt2)) == TYPE_DECL if (odr1 != NULL && odr2 != NULL && odr1 != odr2)
&& DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (mt1)) {
&& DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (mt2)) const int opts = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES;
&& DECL_ASSEMBLER_NAME (TYPE_NAME (mt1)) char *name1 = xstrdup (cplus_demangle (odr1, opts));
!= DECL_ASSEMBLER_NAME (TYPE_NAME (mt2))) char *name2 = xstrdup (cplus_demangle (odr2, opts));
{
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);
if (name1 && name2 && strcmp (name1, name2)) if (name1 && name2 && strcmp (name1, name2))
{ {
inform (loc_t1, inform (loc_t1,
...@@ -3989,4 +3982,20 @@ make_pass_ipa_devirt (gcc::context *ctxt) ...@@ -3989,4 +3982,20 @@ make_pass_ipa_devirt (gcc::context *ctxt)
return new pass_ipa_devirt (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" #include "gt-ipa-devirt.h"
...@@ -248,4 +248,18 @@ odr_type_p (const_tree t) ...@@ -248,4 +248,18 @@ odr_type_p (const_tree t)
&& DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)); && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t));
} }
/* If TYPE has mangled ODR name, return it. Otherwise return NULL.
The function works only when free_lang_data is run. */
inline const char *
get_odr_name_for_type (tree type)
{
tree type_name = TYPE_NAME (type);
if (type_name == NULL_TREE
|| !DECL_ASSEMBLER_NAME_SET_P (type_name))
return NULL;
return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (type_name));
}
#endif /* GCC_IPA_UTILS_H */ #endif /* GCC_IPA_UTILS_H */
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.
2019-11-30 Jan Hubicka <hubicka@ucw.cz> 2019-11-30 Jan Hubicka <hubicka@ucw.cz>
* g++.dg/lto/inline-crossmodule-1_0.C: fix template. * g++.dg/lto/inline-crossmodule-1_0.C: fix template.
......
// { dg-lto-do link }
struct bar // { dg-lto-message "type name 'bar' should match type name 'foobar<float>'" }
{
int xxx;
};
struct foo // { dg-lto-warning "8: 'struct foo' violates the C\\+\\+ One Definition Rule" }
{
bar a;
};
foo myfoo2;
int
main()
{
}
template <class T>
struct foobar
{
int xxx;
T pes;
};
struct foo
{
foobar<float> a;
};
foo myfoo;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment