Do not ICE for incomplete types in ICF (PR ipa/85607).
authorMartin Liska <mliska@suse.cz>
Tue, 22 May 2018 10:50:43 +0000 (12:50 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 22 May 2018 10:50:43 +0000 (10:50 +0000)
2018-05-22  Martin Liska  <mliska@suse.cz>

PR ipa/85607
* ipa-icf.c (sem_item::add_type): Do not ICE for incomplete types.
2018-05-22  Martin Liska  <mliska@suse.cz>

PR ipa/85607
* g++.dg/ipa/pr85607.C: New test.

From-SVN: r260502

gcc/ChangeLog
gcc/ipa-icf.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ipa/pr85607.C [new file with mode: 0644]

index c3ecb0be3a296d820406f5776a8e6a37ea7dbe17..5ef5cbae541222d40fc7ca292e2a2c17169541f8 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-22  Martin Liska  <mliska@suse.cz>
+
+       PR ipa/85607
+       * ipa-icf.c (sem_item::add_type): Do not ICE for incomplete types.
+
 2018-05-22  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/85863
index f974d9f769f95b2c8a0001724abe784cb10fcbc6..37e63fc2ba8a72ab138671d5e239aac9cfdfef37 100644 (file)
@@ -1580,7 +1580,13 @@ sem_item::add_type (const_tree type, inchash::hash &hstate)
     }
   else if (RECORD_OR_UNION_TYPE_P (type))
     {
-      gcc_checking_assert (COMPLETE_TYPE_P (type));
+      /* Incomplete types must be skipped here.  */
+      if (!COMPLETE_TYPE_P (type))
+       {
+         hstate.add_int (RECORD_TYPE);
+         return;
+       }
+
       hashval_t *val = optimizer->m_type_hash_cache.get (type);
 
       if (!val)
@@ -1591,8 +1597,6 @@ sem_item::add_type (const_tree type, inchash::hash &hstate)
          hashval_t hash;
 
          hstate2.add_int (RECORD_TYPE);
-         gcc_assert (COMPLETE_TYPE_P (type));
-
          for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f))
            if (TREE_CODE (f) == FIELD_DECL)
              {
index 939702c3187a3144f0c9c79748d91cc018bc0263..0f109eb4a53b5e067dc76a3a2ec235f40f043e15 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-22  Martin Liska  <mliska@suse.cz>
+
+       PR ipa/85607
+       * g++.dg/ipa/pr85607.C: New test.
+
 2018-05-22  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/85863
diff --git a/gcc/testsuite/g++.dg/ipa/pr85607.C b/gcc/testsuite/g++.dg/ipa/pr85607.C
new file mode 100644 (file)
index 0000000..b47aba2
--- /dev/null
@@ -0,0 +1,14 @@
+// { dg-do compile }
+/* { dg-options "-O2" } */
+
+class A;       // { dg-message "forward declaration of 'class A'" }
+
+A *a;          // { dg-warning "'a' has incomplete type" }
+
+int
+main (int argc, char **argv)
+{
+  delete a;    // { dg-warning "delete" "warn" }
+  // { dg-message "note" "note" { target *-*-* } .-1 }
+  return 0;
+}