aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranil Dey <mkdeyp@gmail.com>2024-08-25 01:25:26 +0530
committerPranil Dey <mkdeyp@gmail.com>2024-10-01 09:48:04 +0530
commitba70ece43622eb4da97455fb78c42c7e9c7f8ce6 (patch)
tree2c392898a8533c4023445a9bc0c3f18bed0fbb7a
parent9a70651a2126e4aceefd2ebec63c0cf15ce83695 (diff)
downloadgcc-ba70ece43622eb4da97455fb78c42c7e9c7f8ce6.zip
gcc-ba70ece43622eb4da97455fb78c42c7e9c7f8ce6.tar.gz
gcc-ba70ece43622eb4da97455fb78c42c7e9c7f8ce6.tar.bz2
Added some functions and fixed some testcase failures
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
-rw-r--r--gcc/ipa-devirt.cc24
-rw-r--r--gcc/ipa-utils.h1
-rw-r--r--gcc/tree-eh.cc27
3 files changed, 51 insertions, 1 deletions
diff --git a/gcc/ipa-devirt.cc b/gcc/ipa-devirt.cc
index a7ce434..17271b0 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 d1da9c3..908b425 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 eec1e6a..4d541b0 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,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;
}
}