]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Added some functions and fixed some testcase failures
authorPranil Dey <mkdeyp@gmail.com>
Sat, 24 Aug 2024 19:55:26 +0000 (01:25 +0530)
committerPranil Dey <mkdeyp@gmail.com>
Tue, 1 Oct 2024 04:18:04 +0000 (09:48 +0530)
1. odr_equivalent_or_derived_p in ipa-devirt.cc
2. same_or_derived_type in in tree-eh.cc
3. Fixed catch-all handling in match_lp function

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

index a7ce434bffb475e9b31e4be1c8d55a5c6476cdfb..17271b089b744fbfcb9909e4ca02c44f64415e7c 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..4d541b08c2fc144a76d09649053895ed8f33e9cc 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,15 @@ bool match_lp(eh_landing_pad lp, vec<tree> *exception_types) {
         while (catch_handler) {
             tree type_list = catch_handler->type_list;
 
+            if(type_list == NULL) {
+                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;
                     }
                 }