https://gcc.gnu.org/g:c16d4a0ae162abc00d97bb73e598ca00d16cf555

commit c16d4a0ae162abc00d97bb73e598ca00d16cf555
Author: Jan Hubicka <hubi...@ucw.cz>
Date:   Tue Aug 27 13:50:32 2024 +0200

    Fix handling of types
    
            * 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.

Diff:
---
 gcc/ipa-devirt.cc | 24 ++++++++++++++++++++++++
 gcc/ipa-utils.h   |  1 +
 gcc/tree-eh.cc    | 26 +++++++++++++++++++++++++-
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-devirt.cc b/gcc/ipa-devirt.cc
index a7ce434bffb4..d6cfcf2c676c 100644
--- a/gcc/ipa-devirt.cc
+++ b/gcc/ipa-devirt.cc
@@ -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
diff --git a/gcc/ipa-utils.h b/gcc/ipa-utils.h
index d1da9c31e09e..908b425e98c5 100644
--- a/gcc/ipa-utils.h
+++ b/gcc/ipa-utils.h
@@ -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);
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index eec1e6af70d7..ab8e00972b06 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -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;
                     }
                 }

Reply via email to