summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0400-PR-gcov-profile-49299.patch
blob: ac84e6a823cdbd8b9a85341bed5b03350807d12f (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
From a9093bc0aa135388aec0930c07f021c85c39dd93 Mon Sep 17 00:00:00 2001
From: jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 7 Jun 2011 09:53:17 +0000
Subject: [PATCH] 	PR gcov-profile/49299
 	* value-prof.c (gimple_ic): Don't assume icall has
 	a fallthru edge.

	* gcc.dg/tree-prof/pr49299-1.c: New test.
	* gcc.dg/tree-prof/pr49299-2.c: New test.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@174739 138bc75d-0d04-0410-961f-82ee72b054a4

index 629f79a..8ee5730 100644
new file mode 100644
index 0000000..dd45baf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/pr49299-1.c
@@ -0,0 +1,34 @@
+/* { dg-options "-O2" } */
+
+__attribute__((noreturn)) void (*fn) (void);
+
+volatile int v;
+
+__attribute__((noreturn)) void
+fn0 (void)
+{
+  __builtin_exit (0);
+}
+
+__attribute__((noreturn)) void
+fn1 (void)
+{
+  __builtin_exit (1);
+}
+
+__attribute__((noinline, noclone)) void
+setfn (__attribute__((noreturn)) void (*x) (void))
+{
+  fn = x;
+}
+
+int
+main ()
+{
+  int i;
+  if (v < 1)
+    setfn (fn0);
+  else
+    setfn (fn1);
+  fn ();
+}
diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr49299-2.c b/gcc/testsuite/gcc.dg/tree-prof/pr49299-2.c
new file mode 100644
index 0000000..220c8c8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/pr49299-2.c
@@ -0,0 +1,34 @@
+/* { dg-options "-O2" } */
+
+void (*fn) (void);
+
+volatile int v;
+
+__attribute__((noreturn)) void
+fn0 (void)
+{
+  __builtin_exit (0);
+}
+
+void
+fn1 (void)
+{
+}
+
+__attribute__((noinline, noclone)) void
+setfn (void (*x) (void))
+{
+  fn = x;
+}
+
+int
+main ()
+{
+  int i;
+  if (v < 1)
+    setfn (fn0);
+  else
+    setfn (fn1);
+  fn ();
+  return 0;
+}
diff --git a/gcc/value-prof.c b/gcc/value-prof.c
index 8491c77..da7c0e5 100644
--- a/gcc/value-prof.c
+++ b/gcc/value-prof.c
@@ -1104,9 +1104,9 @@ gimple_ic (gimple icall_stmt, struct cgraph_node *direct_call,
 {
   gimple dcall_stmt, load_stmt, cond_stmt;
   tree tmp0, tmp1, tmpv, tmp;
-  basic_block cond_bb, dcall_bb, icall_bb, join_bb;
+  basic_block cond_bb, dcall_bb, icall_bb, join_bb = NULL;
   tree optype = build_pointer_type (void_type_node);
-  edge e_cd, e_ci, e_di, e_dj, e_ij;
+  edge e_cd, e_ci, e_di, e_dj = NULL, e_ij;
   gimple_stmt_iterator gsi;
   int lp_nr;
 
@@ -1153,12 +1153,19 @@ gimple_ic (gimple icall_stmt, struct cgraph_node *direct_call,
   else
     {
       e_ij = find_fallthru_edge (icall_bb->succs);
-      e_ij->probability = REG_BR_PROB_BASE;
-      e_ij->count = all - count;
-      e_ij = single_pred_edge (split_edge (e_ij));
+      /* The indirect call might be noreturn.  */
+      if (e_ij != NULL)
+	{
+	  e_ij->probability = REG_BR_PROB_BASE;
+	  e_ij->count = all - count;
+	  e_ij = single_pred_edge (split_edge (e_ij));
+	}
+    }
+  if (e_ij != NULL)
+    {
+      join_bb = e_ij->dest;
+      join_bb->count = all;
     }
-  join_bb = e_ij->dest;
-  join_bb->count = all;
 
   e_cd->flags = (e_cd->flags & ~EDGE_FALLTHRU) | EDGE_TRUE_VALUE;
   e_cd->probability = prob;
@@ -1170,12 +1177,15 @@ gimple_ic (gimple icall_stmt, struct cgraph_node *direct_call,
 
   remove_edge (e_di);
 
-  e_dj = make_edge (dcall_bb, join_bb, EDGE_FALLTHRU);
-  e_dj->probability = REG_BR_PROB_BASE;
-  e_dj->count = count;
+  if (e_ij != NULL)
+    {
+      e_dj = make_edge (dcall_bb, join_bb, EDGE_FALLTHRU);
+      e_dj->probability = REG_BR_PROB_BASE;
+      e_dj->count = count;
 
-  e_ij->probability = REG_BR_PROB_BASE;
-  e_ij->count = all - count;
+      e_ij->probability = REG_BR_PROB_BASE;
+      e_ij->count = all - count;
+    }
 
   /* Insert PHI node for the call result if necessary.  */
   if (gimple_call_lhs (icall_stmt)
-- 
1.7.0.4