summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0014-2011-03-28-Richard-Guenther-rguenther-suse.de.patch
blob: e5ae726cdedafae3ae179f5c21593c9f3f167abb (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
Upstream-Status: Inappropriate [Backport]
From 2631216d2fedc5339a5edcac64db1ab5d9269498 Mon Sep 17 00:00:00 2001
From: rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 28 Mar 2011 10:14:34 +0000
Subject: [PATCH 014/200] 2011-03-28  Richard Guenther  <rguenther@suse.de>

	Backport from mainline
	2011-03-24  Richard Guenther  <rguenther@suse.de>

	PR middle-end/48269
	* tree-object-size.c (addr_object_size): Do not double-account
	for MEM_REF offsets.

	* gcc.dg/builtin-object-size-10.c: New testcase.

	2011-03-22  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/48228
	* tree-vrp.c (vrp_visit_phi_node): Do not stop propagating
	for single-arg PHIs.

	* gcc.dg/Wstrict-overflow-23.c: New testcase.

	2011-03-17  Richard Guenther  <rguenther@suse.de>

	PR middle-end/48134
	* tree-ssa.c (insert_debug_temp_for_var_def): If we propagated
	a value make sure to fold the statement.

	* gcc.dg/pr48134.c: New testcase.

	2011-03-15  Richard Guenther  <rguenther@suse.de>

	PR middle-end/48031
	* fold-const.c (fold_indirect_ref_1): Do not create new variable-sized
	or variable-indexed array accesses when in gimple form.


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

index 957049c..9a2f31f 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -15554,12 +15554,17 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
 	}
       /* *(foo *)&fooarray => fooarray[0] */
       else if (TREE_CODE (optype) == ARRAY_TYPE
-	       && type == TREE_TYPE (optype))
+	       && type == TREE_TYPE (optype)
+	       && (!in_gimple_form
+		   || TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST))
 	{
 	  tree type_domain = TYPE_DOMAIN (optype);
 	  tree min_val = size_zero_node;
 	  if (type_domain && TYPE_MIN_VALUE (type_domain))
 	    min_val = TYPE_MIN_VALUE (type_domain);
+	  if (in_gimple_form
+	      && TREE_CODE (min_val) != INTEGER_CST)
+	    return NULL_TREE;
 	  return build4_loc (loc, ARRAY_REF, type, op, min_val,
 			     NULL_TREE, NULL_TREE);
 	}
@@ -15633,7 +15638,9 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
 
   /* *(foo *)fooarrptr => (*fooarrptr)[0] */
   if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE
-      && type == TREE_TYPE (TREE_TYPE (subtype)))
+      && type == TREE_TYPE (TREE_TYPE (subtype))
+      && (!in_gimple_form
+	  || TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST))
     {
       tree type_domain;
       tree min_val = size_zero_node;
@@ -15641,6 +15648,9 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
       type_domain = TYPE_DOMAIN (TREE_TYPE (sub));
       if (type_domain && TYPE_MIN_VALUE (type_domain))
 	min_val = TYPE_MIN_VALUE (type_domain);
+      if (in_gimple_form
+	  && TREE_CODE (min_val) != INTEGER_CST)
+	return NULL_TREE;
       return build4_loc (loc, ARRAY_REF, type, sub, min_val, NULL_TREE,
 			 NULL_TREE);
     }
new file mode 100644
index 0000000..16014bb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wstrict-overflow-23.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wstrict-overflow" } */
+
+unsigned int
+do_scrolling (unsigned int window_size, unsigned int writecost)
+{
+  unsigned int i = window_size;
+
+  int terminal_window_p = 0;
+  unsigned int queue = 0;
+
+  for (i = window_size; i; i--)
+    {
+      if (writecost < i)
+    ++queue;
+      else if (writecost & 1)
+    terminal_window_p = 1;
+    }
+
+  if (queue > 0)
+    {
+      if (!terminal_window_p)
+    {
+      terminal_window_p = 1;
+    }
+    }
+
+  if (terminal_window_p)
+    return 100;
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-10.c b/gcc/testsuite/gcc.dg/builtin-object-size-10.c
new file mode 100644
index 0000000..6c7ed45
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-10.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-objsz-details" } */
+
+typedef struct {
+    char sentinel[4];
+    char data[0];
+} drone_packet;
+typedef struct {
+    char type_str[16];
+    char channel_hop;
+} drone_source_packet;
+drone_packet *
+foo(char *x)
+{
+  drone_packet *dpkt = __builtin_malloc(sizeof(drone_packet)
+					+ sizeof(drone_source_packet));
+  drone_source_packet *spkt = (drone_source_packet *) dpkt->data;
+  __builtin___snprintf_chk (spkt->type_str, 16,
+			    1, __builtin_object_size (spkt->type_str, 1),
+			    "%s", x);
+  return dpkt;
+}
+
+/* { dg-final { scan-tree-dump "maximum object size 21" "objsz" } } */
+/* { dg-final { scan-tree-dump "maximum subobject size 16" "objsz" } } */
+/* { dg-final { cleanup-tree-dump "objsz" } } */
diff --git a/gcc/testsuite/gcc.dg/pr48134.c b/gcc/testsuite/gcc.dg/pr48134.c
new file mode 100644
index 0000000..8dc5a6d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr48134.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fstack-check=specific -fno-tree-dse -fno-tree-fre -fno-tree-loop-optimize -g" } */
+
+struct S
+{
+  int w, z;
+};
+struct T
+{
+  struct S s;
+};
+
+int i;
+
+static inline struct S
+bar (struct S x)
+{
+  i++;
+  return x;
+}
+
+int
+foo (struct T t, struct S s)
+{
+  struct S *c = &s;
+  if (i)
+    c = &t.s;
+  t.s.w = 3;
+  s = bar (*c);
+  return t.s.w;
+}
diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
index 6a74d19..043b445 100644
--- a/gcc/tree-object-size.c
+++ b/gcc/tree-object-size.c
@@ -348,8 +348,6 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
 	  tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0), pt_var);
 	  if (bytes2 != error_mark_node)
 	    {
-	      bytes2 = size_binop (PLUS_EXPR, bytes2,
-				   TREE_OPERAND (pt_var, 1));
 	      if (TREE_CODE (bytes2) == INTEGER_CST
 		  && tree_int_cst_lt (pt_var_size, bytes2))
 		bytes2 = size_zero_node;
diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c
index 5c9e0d8..eaf3ef9 100644
--- a/gcc/tree-ssa.c
+++ b/gcc/tree-ssa.c
@@ -455,13 +455,19 @@ insert_debug_temp_for_var_def (gimple_stmt_iterator *gsi, tree var)
 	continue;
 
       if (value)
-	FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
-	  /* unshare_expr is not needed here.  vexpr is either a
-	     SINGLE_RHS, that can be safely shared, some other RHS
-	     that was unshared when we found it had a single debug
-	     use, or a DEBUG_EXPR_DECL, that can be safely
-	     shared.  */
-	  SET_USE (use_p, value);
+	{
+	  FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
+	    /* unshare_expr is not needed here.  vexpr is either a
+	       SINGLE_RHS, that can be safely shared, some other RHS
+	       that was unshared when we found it had a single debug
+	       use, or a DEBUG_EXPR_DECL, that can be safely
+	       shared.  */
+	    SET_USE (use_p, value);
+	  /* If we didn't replace uses with a debug decl fold the
+	     resulting expression.  Otherwise we end up with invalid IL.  */
+	  if (TREE_CODE (value) != DEBUG_EXPR_DECL)
+	    fold_stmt_inplace (stmt);
+	}
       else
 	gimple_debug_bind_reset_value (stmt);
 
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 65d249f..280e6da 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -6619,6 +6619,7 @@ vrp_visit_phi_node (gimple phi)
      edge; this helps us avoid an overflow infinity for conditionals
      which are not in a loop.  */
   if (edges > 0
+      && gimple_phi_num_args (phi) > 1
       && edges == old_edges)
     {
       int cmp_min = compare_values (lhs_vr->min, vr_result.min);
-- 
1.7.0.4

OpenPOWER on IntegriCloud