]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix handling of types
authorJan Hubicka <hubicka@ucw.cz>
Tue, 27 Aug 2024 11:50:32 +0000 (13:50 +0200)
committerJan Hubicka <hubicka@ucw.cz>
Tue, 27 Aug 2024 11:50:32 +0000 (13:50 +0200)
* ipa-devirt.cc (odr_equivalent_or_derived_p): New.
* ipa-utils.h (odr_equivalent_or_derived_p): Declare.
* tree-eh.cc (same_or_derived_type): New.
(match_lp): Use it.

gcc/ipa-devirt.cc
gcc/ipa-utils.h
gcc/tree-eh.cc

index a7ce434bffb475e9b31e4be1c8d55a5c6476cdfb..d6cfcf2c676c425266db7b9979876ed6e6b840cf 100644 (file)
@@ -1211,6 +1211,30 @@ skip_in_fields_list_p (tree t)
   return false;
 }
 
+/* Return true if T2 is derived form T1.  */
+
+bool
+odr_equivalent_or_derived_p (tree t1, tree t2)
+{
+  if (in_lto_p)
+    {
+      if (odr_types_equivalent_p (t1, t2))
+       return true;
+    }
+  else
+    {
+      if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
+       return true;
+    }
+  if (!TYPE_BINFO (t2))
+    return false;
+  for (unsigned int i = 0; i < BINFO_N_BASE_BINFOS (TYPE_BINFO (t2)); i++)
+    if (odr_equivalent_or_derived_p
+        (t1, BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t2), i))))
+    return true;
+  return false;
+}
+
 /* Compare T1 and T2, report ODR violations if WARN is true and set
    WARNED to true if anything is reported.  Return true if types match.
    If true is returned, the types are also compatible in the sense of
index d1da9c31e09ed6d7d29a60d8d4e172b902902141..908b425e98c5e93f00bd387d76ee87dff9e8dc2d 100644 (file)
@@ -106,6 +106,7 @@ cgraph_node *try_speculative_devirtualization (tree, HOST_WIDE_INT,
 void warn_types_mismatch (tree t1, tree t2, location_t loc1 = UNKNOWN_LOCATION,
                          location_t loc2 = UNKNOWN_LOCATION);
 bool odr_or_derived_type_p (const_tree t);
+bool odr_equivalent_or_derived_p (tree t1, tree t2);
 bool odr_types_equivalent_p (tree type1, tree type2);
 bool odr_type_violation_reported_p (tree type);
 tree prevailing_odr_type (tree type);
index eec1e6af70d7a13ee3800d2179a647a32af411eb..ab8e00972b06e0f7cecef1bfb73d09bdd817e42d 100644 (file)
@@ -47,6 +47,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "attribs.h"
 #include "asan.h"
 #include "gimplify.h"
+#include "print-tree.h"
+#include "ipa-utils.h"
 
 /* In some instances a tree and a gimple need to be stored in a same table,
    i.e. in hash tables. This is a structure to do this. */
@@ -2270,6 +2272,25 @@ make_eh_dispatch_edges (geh_dispatch *stmt)
 
   return true;
 }
+bool
+same_or_derived_type (tree t1, tree t2)
+{
+  t1 = TYPE_MAIN_VARIANT (t1);
+  t2 = TYPE_MAIN_VARIANT (t2);
+  if (t1 == t2)
+    return true;
+  while ((TREE_CODE (t1) == POINTER_TYPE || TREE_CODE (t1) == REFERENCE_TYPE)
+        && TREE_CODE (t1) == TREE_CODE (t2))
+  {
+    t1 = TYPE_MAIN_VARIANT (TREE_TYPE (t1));
+    t2 = TYPE_MAIN_VARIANT (TREE_TYPE (t2));
+  }
+  if (t1 == t2)
+    return true;
+  if (!AGGREGATE_TYPE_P (t1) || !AGGREGATE_TYPE_P (t2))
+    return false;
+  return odr_equivalent_or_derived_p (t1, t2);
+}
 
 // Check if a landing pad can handle any of the given exception types
 bool match_lp(eh_landing_pad lp, vec<tree> *exception_types) {
@@ -2282,11 +2303,14 @@ bool match_lp(eh_landing_pad lp, vec<tree> *exception_types) {
         while (catch_handler) {
             tree type_list = catch_handler->type_list;
 
+           if (!type_list)
+             return true;
+
             for (tree t = type_list; t; t = TREE_CHAIN(t)) {
                 tree type = TREE_VALUE(t);
                 for (unsigned i = 0; i < exception_types->length(); ++i) {
                   // match found or a catch-all handler (NULL)
-                    if (type == (*exception_types)[i] || !type) {
+                    if (!type || same_or_derived_type ((*exception_types)[i], type)) {
                         return true;
                     }
                 }