]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/blob
e5ae726cdedafae3ae179f5c21593c9f3f167abb
[thirdparty/openembedded/openembedded-core-contrib.git] /
1 Upstream-Status: Inappropriate [Backport]
2 From 2631216d2fedc5339a5edcac64db1ab5d9269498 Mon Sep 17 00:00:00 2001
3 From: rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
4 Date: Mon, 28 Mar 2011 10:14:34 +0000
5 Subject: [PATCH 014/200] 2011-03-28 Richard Guenther <rguenther@suse.de>
6
7 Backport from mainline
8 2011-03-24 Richard Guenther <rguenther@suse.de>
9
10 PR middle-end/48269
11 * tree-object-size.c (addr_object_size): Do not double-account
12 for MEM_REF offsets.
13
14 * gcc.dg/builtin-object-size-10.c: New testcase.
15
16 2011-03-22 Richard Guenther <rguenther@suse.de>
17
18 PR tree-optimization/48228
19 * tree-vrp.c (vrp_visit_phi_node): Do not stop propagating
20 for single-arg PHIs.
21
22 * gcc.dg/Wstrict-overflow-23.c: New testcase.
23
24 2011-03-17 Richard Guenther <rguenther@suse.de>
25
26 PR middle-end/48134
27 * tree-ssa.c (insert_debug_temp_for_var_def): If we propagated
28 a value make sure to fold the statement.
29
30 * gcc.dg/pr48134.c: New testcase.
31
32 2011-03-15 Richard Guenther <rguenther@suse.de>
33
34 PR middle-end/48031
35 * fold-const.c (fold_indirect_ref_1): Do not create new variable-sized
36 or variable-indexed array accesses when in gimple form.
37
38
39 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@171595 138bc75d-0d04-0410-961f-82ee72b054a4
40
41 index 957049c..9a2f31f 100644
42 --- a/gcc/fold-const.c
43 +++ b/gcc/fold-const.c
44 @@ -15554,12 +15554,17 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
45 }
46 /* *(foo *)&fooarray => fooarray[0] */
47 else if (TREE_CODE (optype) == ARRAY_TYPE
48 - && type == TREE_TYPE (optype))
49 + && type == TREE_TYPE (optype)
50 + && (!in_gimple_form
51 + || TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST))
52 {
53 tree type_domain = TYPE_DOMAIN (optype);
54 tree min_val = size_zero_node;
55 if (type_domain && TYPE_MIN_VALUE (type_domain))
56 min_val = TYPE_MIN_VALUE (type_domain);
57 + if (in_gimple_form
58 + && TREE_CODE (min_val) != INTEGER_CST)
59 + return NULL_TREE;
60 return build4_loc (loc, ARRAY_REF, type, op, min_val,
61 NULL_TREE, NULL_TREE);
62 }
63 @@ -15633,7 +15638,9 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
64
65 /* *(foo *)fooarrptr => (*fooarrptr)[0] */
66 if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE
67 - && type == TREE_TYPE (TREE_TYPE (subtype)))
68 + && type == TREE_TYPE (TREE_TYPE (subtype))
69 + && (!in_gimple_form
70 + || TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST))
71 {
72 tree type_domain;
73 tree min_val = size_zero_node;
74 @@ -15641,6 +15648,9 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
75 type_domain = TYPE_DOMAIN (TREE_TYPE (sub));
76 if (type_domain && TYPE_MIN_VALUE (type_domain))
77 min_val = TYPE_MIN_VALUE (type_domain);
78 + if (in_gimple_form
79 + && TREE_CODE (min_val) != INTEGER_CST)
80 + return NULL_TREE;
81 return build4_loc (loc, ARRAY_REF, type, sub, min_val, NULL_TREE,
82 NULL_TREE);
83 }
84 new file mode 100644
85 index 0000000..16014bb
86 --- /dev/null
87 +++ b/gcc/testsuite/gcc.dg/Wstrict-overflow-23.c
88 @@ -0,0 +1,31 @@
89 +/* { dg-do compile } */
90 +/* { dg-options "-O2 -Wstrict-overflow" } */
91 +
92 +unsigned int
93 +do_scrolling (unsigned int window_size, unsigned int writecost)
94 +{
95 + unsigned int i = window_size;
96 +
97 + int terminal_window_p = 0;
98 + unsigned int queue = 0;
99 +
100 + for (i = window_size; i; i--)
101 + {
102 + if (writecost < i)
103 + ++queue;
104 + else if (writecost & 1)
105 + terminal_window_p = 1;
106 + }
107 +
108 + if (queue > 0)
109 + {
110 + if (!terminal_window_p)
111 + {
112 + terminal_window_p = 1;
113 + }
114 + }
115 +
116 + if (terminal_window_p)
117 + return 100;
118 + return 0;
119 +}
120 diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-10.c b/gcc/testsuite/gcc.dg/builtin-object-size-10.c
121 new file mode 100644
122 index 0000000..6c7ed45
123 --- /dev/null
124 +++ b/gcc/testsuite/gcc.dg/builtin-object-size-10.c
125 @@ -0,0 +1,26 @@
126 +/* { dg-do compile } */
127 +/* { dg-options "-O2 -fdump-tree-objsz-details" } */
128 +
129 +typedef struct {
130 + char sentinel[4];
131 + char data[0];
132 +} drone_packet;
133 +typedef struct {
134 + char type_str[16];
135 + char channel_hop;
136 +} drone_source_packet;
137 +drone_packet *
138 +foo(char *x)
139 +{
140 + drone_packet *dpkt = __builtin_malloc(sizeof(drone_packet)
141 + + sizeof(drone_source_packet));
142 + drone_source_packet *spkt = (drone_source_packet *) dpkt->data;
143 + __builtin___snprintf_chk (spkt->type_str, 16,
144 + 1, __builtin_object_size (spkt->type_str, 1),
145 + "%s", x);
146 + return dpkt;
147 +}
148 +
149 +/* { dg-final { scan-tree-dump "maximum object size 21" "objsz" } } */
150 +/* { dg-final { scan-tree-dump "maximum subobject size 16" "objsz" } } */
151 +/* { dg-final { cleanup-tree-dump "objsz" } } */
152 diff --git a/gcc/testsuite/gcc.dg/pr48134.c b/gcc/testsuite/gcc.dg/pr48134.c
153 new file mode 100644
154 index 0000000..8dc5a6d
155 --- /dev/null
156 +++ b/gcc/testsuite/gcc.dg/pr48134.c
157 @@ -0,0 +1,31 @@
158 +/* { dg-do compile } */
159 +/* { dg-options "-O2 -fstack-check=specific -fno-tree-dse -fno-tree-fre -fno-tree-loop-optimize -g" } */
160 +
161 +struct S
162 +{
163 + int w, z;
164 +};
165 +struct T
166 +{
167 + struct S s;
168 +};
169 +
170 +int i;
171 +
172 +static inline struct S
173 +bar (struct S x)
174 +{
175 + i++;
176 + return x;
177 +}
178 +
179 +int
180 +foo (struct T t, struct S s)
181 +{
182 + struct S *c = &s;
183 + if (i)
184 + c = &t.s;
185 + t.s.w = 3;
186 + s = bar (*c);
187 + return t.s.w;
188 +}
189 diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
190 index 6a74d19..043b445 100644
191 --- a/gcc/tree-object-size.c
192 +++ b/gcc/tree-object-size.c
193 @@ -348,8 +348,6 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
194 tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0), pt_var);
195 if (bytes2 != error_mark_node)
196 {
197 - bytes2 = size_binop (PLUS_EXPR, bytes2,
198 - TREE_OPERAND (pt_var, 1));
199 if (TREE_CODE (bytes2) == INTEGER_CST
200 && tree_int_cst_lt (pt_var_size, bytes2))
201 bytes2 = size_zero_node;
202 diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c
203 index 5c9e0d8..eaf3ef9 100644
204 --- a/gcc/tree-ssa.c
205 +++ b/gcc/tree-ssa.c
206 @@ -455,13 +455,19 @@ insert_debug_temp_for_var_def (gimple_stmt_iterator *gsi, tree var)
207 continue;
208
209 if (value)
210 - FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
211 - /* unshare_expr is not needed here. vexpr is either a
212 - SINGLE_RHS, that can be safely shared, some other RHS
213 - that was unshared when we found it had a single debug
214 - use, or a DEBUG_EXPR_DECL, that can be safely
215 - shared. */
216 - SET_USE (use_p, value);
217 + {
218 + FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
219 + /* unshare_expr is not needed here. vexpr is either a
220 + SINGLE_RHS, that can be safely shared, some other RHS
221 + that was unshared when we found it had a single debug
222 + use, or a DEBUG_EXPR_DECL, that can be safely
223 + shared. */
224 + SET_USE (use_p, value);
225 + /* If we didn't replace uses with a debug decl fold the
226 + resulting expression. Otherwise we end up with invalid IL. */
227 + if (TREE_CODE (value) != DEBUG_EXPR_DECL)
228 + fold_stmt_inplace (stmt);
229 + }
230 else
231 gimple_debug_bind_reset_value (stmt);
232
233 diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
234 index 65d249f..280e6da 100644
235 --- a/gcc/tree-vrp.c
236 +++ b/gcc/tree-vrp.c
237 @@ -6619,6 +6619,7 @@ vrp_visit_phi_node (gimple phi)
238 edge; this helps us avoid an overflow infinity for conditionals
239 which are not in a loop. */
240 if (edges > 0
241 + && gimple_phi_num_args (phi) > 1
242 && edges == old_edges)
243 {
244 int cmp_min = compare_values (lhs_vr->min, vr_result.min);
245 --
246 1.7.0.4
247