summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2019-12-10 09:17:34 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2019-12-10 09:17:34 +0000
commitc175aa77aa8a4ba1d950f2db8c66cee004888212 (patch)
treee0e7b28f231b9b7921cce8533c7e8ea2744ba78b
parent8cf23a6f80d47aff386a9a260d198696b50c9416 (diff)
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 <richard.sandiford@arm.com> 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
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/ipa-devirt.c2
-rw-r--r--gcc/ipa-utils.h1
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/lto/tag-1_0.c5
-rw-r--r--gcc/testsuite/gcc.dg/lto/tag-1_1.c6
6 files changed, 23 insertions, 1 deletions
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 <richard.sandiford@arm.com>
+
+ * 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 <jakub@redhat.com>
* 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 <richard.sandiford@arm.com>
+
+ * gcc.dg/lto/tag-1_0.c, gcc.dg/lto/tag-1_1.c: New test.
+
2019-12-10 Jakub Jelinek <jakub@redhat.com>
* 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; }