From c175aa77aa8a4ba1d950f2db8c66cee004888212 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Tue, 10 Dec 2019 09:17:34 +0000 Subject: [PATCH] Check for TYPE_DECL in get_odr_name_for_type Make get_odr_name_for_type check for TYPE_DECL in the way that its caller warn_types_mismatch previously did. 2019-12-10 Richard Sandiford gcc/ * ipa-utils.h (get_odr_name_for_type): Check for a TYPE_DECL. * ipa-devirt.c (warn_types_mismatch): Don't call xstrdup for the second demangled name. gcc/testsuite/ * gcc.dg/lto/tag-1_0.c, gcc.dg/lto/tag-1_1.c: New test. From-SVN: r279159 --- gcc/ChangeLog | 6 ++++++ gcc/ipa-devirt.c | 2 +- gcc/ipa-utils.h | 1 + gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/lto/tag-1_0.c | 5 +++++ gcc/testsuite/gcc.dg/lto/tag-1_1.c | 6 ++++++ 6 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/lto/tag-1_0.c create mode 100644 gcc/testsuite/gcc.dg/lto/tag-1_1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 73ee149fb8d..21a80953221 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-12-10 Richard Sandiford + + * ipa-utils.h (get_odr_name_for_type): Check for a TYPE_DECL. + * ipa-devirt.c (warn_types_mismatch): Don't call xstrdup for the + second demangled name. + 2019-12-10 Jakub Jelinek * config/i386/i386.c (IX86_LEA_PRIORITY): Fix comment typos. diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c index 1017b2a5c7c..6aa62779843 100644 --- a/gcc/ipa-devirt.c +++ b/gcc/ipa-devirt.c @@ -1042,7 +1042,7 @@ warn_types_mismatch (tree t1, tree t2, location_t loc1, location_t loc2) { const int opts = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES; char *name1 = xstrdup (cplus_demangle (odr1, opts)); - char *name2 = xstrdup (cplus_demangle (odr2, opts)); + char *name2 = cplus_demangle (odr2, opts); if (name1 && name2 && strcmp (name1, name2)) { inform (loc_t1, diff --git a/gcc/ipa-utils.h b/gcc/ipa-utils.h index 81a54797558..411a478353b 100644 --- a/gcc/ipa-utils.h +++ b/gcc/ipa-utils.h @@ -256,6 +256,7 @@ get_odr_name_for_type (tree type) { tree type_name = TYPE_NAME (type); if (type_name == NULL_TREE + || TREE_CODE (type_name) != TYPE_DECL || !DECL_ASSEMBLER_NAME_SET_P (type_name)) return NULL; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fb38258f1f8..7ba847da113 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-12-10 Richard Sandiford + + * gcc.dg/lto/tag-1_0.c, gcc.dg/lto/tag-1_1.c: New test. + 2019-12-10 Jakub Jelinek * gcc.target/i386/avx512f-vmovntpd-2.c: Ensure res is 64-byte aligned. diff --git a/gcc/testsuite/gcc.dg/lto/tag-1_0.c b/gcc/testsuite/gcc.dg/lto/tag-1_0.c new file mode 100644 index 00000000000..c9b0c719f4e --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/tag-1_0.c @@ -0,0 +1,5 @@ +/* { dg-lto-do link } */ +/* { dg-lto-options { { -Wodr -flto } } } */ + +struct foo { int x; }; +struct foo a = {}; diff --git a/gcc/testsuite/gcc.dg/lto/tag-1_1.c b/gcc/testsuite/gcc.dg/lto/tag-1_1.c new file mode 100644 index 00000000000..443f9109811 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/tag-1_1.c @@ -0,0 +1,6 @@ +struct foo { short x; }; + +extern struct foo a; /* { dg-lto-warning {type of 'a' does not match original declaration} } */ +struct foo *ptr = &a; + +int main () { return 0; } -- 2.30.2