]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Check for TYPE_DECL in get_odr_name_for_type
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 10 Dec 2019 09:17:34 +0000 (09:17 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Tue, 10 Dec 2019 09:17:34 +0000 (09:17 +0000)
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

gcc/ChangeLog
gcc/ipa-devirt.c
gcc/ipa-utils.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/lto/tag-1_0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/lto/tag-1_1.c [new file with mode: 0644]

index 73ee149fb8d930267b150b8dbaf2e2d8fc511493..21a809532218e445e838db5af507799eca58e4c1 100644 (file)
@@ -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.
index 1017b2a5c7cdcee2de34f558fdb7644f251a7640..6aa627798434fefba643821c72633987ef52d02e 100644 (file)
@@ -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,
index 81a5479755888aaf54413cf16b423cafa326bd81..411a478353bfc74439077fea31c9797aa9ebb858 100644 (file)
@@ -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;
 
index fb38258f1f850c3bf8fe2d6535ba363cba0aed46..7ba847da113deaaf258332af520954ff4e4df76f 100644 (file)
@@ -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 (file)
index 0000000..c9b0c71
--- /dev/null
@@ -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 (file)
index 0000000..443f910
--- /dev/null
@@ -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; }