summaryrefslogtreecommitdiff
path: root/0041-Port-fixes-in-icp-to-GCC-12.patch
blob: 723f8b074caf1b33cdbca7e49ece489fcb4a7ba7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From aaa117a9ff58fb208e8c8859e075ca425f995f63 Mon Sep 17 00:00:00 2001
From: Diachkov Ilia <diachkov.ilia1@huawei-partners.com>
Date: Tue, 27 Feb 2024 07:43:57 +0800
Subject: [PATCH 07/18] Port fixes in icp to GCC 12

---
 gcc/ipa-devirt.cc | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/gcc/ipa-devirt.cc b/gcc/ipa-devirt.cc
index 383839189..318535d06 100644
--- a/gcc/ipa-devirt.cc
+++ b/gcc/ipa-devirt.cc
@@ -4431,6 +4431,11 @@ print_type_set(unsigned ftype_uid, type_alias_map *map)
   if (!map->count (ftype_uid))
     return;
   type_set* s = (*map)[ftype_uid];
+  if (!s)
+    {
+      fprintf (dump_file, "%d (no set)", ftype_uid);
+      return;
+    }
   for (type_set::const_iterator it = s->begin (); it != s->end (); it++)
     fprintf (dump_file, it == s->begin () ? "%d" : ", %d", *it);
 }
@@ -4696,12 +4701,19 @@ maybe_register_aliases (tree type1, tree type2)
       if (register_ailas_type (type1, type2, ta_map))
 	analyze_pointees (type1, type2);
     }
+  unsigned type1_uid = TYPE_UID (type1);
+  unsigned type2_uid = TYPE_UID (type2);
+  if (type_uid_map->count (type1_uid) == 0)
+    (*type_uid_map)[type1_uid] = type1;
+  if (type_uid_map->count (type2_uid) == 0)
+    (*type_uid_map)[type2_uid] = type2;
+
   /* If function and non-function type pointers alias,
      the function type is unsafe.  */
   if (FUNCTION_POINTER_TYPE_P (type1) && !FUNCTION_POINTER_TYPE_P (type2))
-    unsafe_types->insert (TYPE_UID (type1));
+    unsafe_types->insert (type1_uid);
   if (FUNCTION_POINTER_TYPE_P (type2) && !FUNCTION_POINTER_TYPE_P (type1))
-    unsafe_types->insert (TYPE_UID (type2));
+    unsafe_types->insert (type2_uid);
 
   /* Try to figure out with pointers to incomplete types.  */
   if (POINTER_TYPE_P (type1) && POINTER_TYPE_P (type2))
@@ -4825,10 +4837,12 @@ compare_block_and_init_type (tree block, tree t1)
 static void
 analyze_global_var (varpool_node *var)
 {
-  var->get_constructor();
   tree decl = var->decl;
-  if (TREE_CODE (decl) == SSA_NAME || !DECL_INITIAL (decl)
-      || integer_zerop (DECL_INITIAL (decl)))
+  if (decl || !DECL_INITIAL (decl))
+    return;
+  var->get_constructor ();
+  if (TREE_CODE (decl) == SSA_NAME || integer_zerop (DECL_INITIAL (decl))
+      || TREE_CODE (DECL_INITIAL (decl)) == ERROR_MARK)
     return;
 
   if (dump_file && (dump_flags & TDF_DETAILS))
@@ -4998,7 +5012,9 @@ analyze_assign_stmt (gimple *stmt)
     {
       rhs = TREE_OPERAND (rhs, 0);
       if (VAR_OR_FUNCTION_DECL_P (rhs) || TREE_CODE (rhs) == STRING_CST
-	  || TREE_CODE (rhs) == ARRAY_REF || TREE_CODE (rhs) == PARM_DECL)
+	  || TREE_CODE (rhs) == ARRAY_REF || TREE_CODE (rhs) == PARM_DECL
+	  || TREE_CODE (rhs) == LABEL_DECL || TREE_CODE (rhs) == CONST_DECL
+	  || TREE_CODE (rhs) == RESULT_DECL)
 	rhs_type = build_pointer_type (TREE_TYPE (rhs));
       else if (TREE_CODE (rhs) == COMPONENT_REF)
 	{
@@ -5012,7 +5028,12 @@ analyze_assign_stmt (gimple *stmt)
 	  gcc_assert (POINTER_TYPE_P (rhs_type));
 	}
       else
-	gcc_unreachable();
+	{
+	  fprintf (dump_file, "\nUnsupported rhs type %s in assign stmt: ",
+		   get_tree_code_name (TREE_CODE (rhs)));
+	  print_gimple_stmt (dump_file, stmt, 0);
+	  gcc_unreachable ();
+	}
     }
   else
     rhs_type = TREE_TYPE (rhs);
@@ -5710,6 +5731,8 @@ merge_fs_map_for_ftype_aliases ()
       decl_set *d_set = it1->second;
       tree type = (*type_uid_map)[it1->first];
       type_set *set = (*fta_map)[it1->first];
+      if (!set)
+	continue;
       for (type_set::const_iterator it2 = set->begin ();
 	   it2 != set->end (); it2++)
 	{
-- 
2.33.0