Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/hardened-patchset:master commit in: 2.6.32/, 3.2.27/, 3.5.2/
Date: Thu, 23 Aug 2012 09:22:32
Message-Id: 1345713695.a89caf05a86e0a5b4b1e4995e935988d7ccb52a2.blueness@gentoo
1 commit: a89caf05a86e0a5b4b1e4995e935988d7ccb52a2
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Thu Aug 23 09:21:35 2012 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Thu Aug 23 09:21:35 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/hardened-patchset.git;a=commit;h=a89caf05
7
8 Grsec/PaX: 2.9.1-{2.6.32.59,3.2.27,3.5.2}-201208201521
9
10 ---
11 2.6.32/0000_README | 2 +-
12 ..._grsecurity-2.9.1-2.6.32.59-201208201521.patch} | 417 +++++++++++---------
13 3.2.27/0000_README | 2 +-
14 ...420_grsecurity-2.9.1-3.2.27-201208201521.patch} | 417 +++++++++++---------
15 3.5.2/0000_README | 2 +-
16 ...4420_grsecurity-2.9.1-3.5.2-201208201522.patch} | 417 +++++++++++---------
17 6 files changed, 678 insertions(+), 579 deletions(-)
18
19 diff --git a/2.6.32/0000_README b/2.6.32/0000_README
20 index 1250ead..0ba8a80 100644
21 --- a/2.6.32/0000_README
22 +++ b/2.6.32/0000_README
23 @@ -30,7 +30,7 @@ Patch: 1058_linux-2.6.32.59.patch
24 From: http://www.kernel.org
25 Desc: Linux 2.6.32.59
26
27 -Patch: 4420_grsecurity-2.9.1-2.6.32.59-201208151950.patch
28 +Patch: 4420_grsecurity-2.9.1-2.6.32.59-201208201521.patch
29 From: http://www.grsecurity.net
30 Desc: hardened-sources base patch from upstream grsecurity
31
32
33 diff --git a/2.6.32/4420_grsecurity-2.9.1-2.6.32.59-201208151950.patch b/2.6.32/4420_grsecurity-2.9.1-2.6.32.59-201208201521.patch
34 similarity index 99%
35 rename from 2.6.32/4420_grsecurity-2.9.1-2.6.32.59-201208151950.patch
36 rename to 2.6.32/4420_grsecurity-2.9.1-2.6.32.59-201208201521.patch
37 index ad50ae4..c356bad 100644
38 --- a/2.6.32/4420_grsecurity-2.9.1-2.6.32.59-201208151950.patch
39 +++ b/2.6.32/4420_grsecurity-2.9.1-2.6.32.59-201208201521.patch
40 @@ -110277,7 +110277,7 @@ index 0000000..048d4ff
41 +}
42 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
43 new file mode 100644
44 -index 0000000..a0fe8b2
45 +index 0000000..68b646e
46 --- /dev/null
47 +++ b/tools/gcc/generate_size_overflow_hash.sh
48 @@ -0,0 +1,94 @@
49 @@ -110334,7 +110334,7 @@ index 0000000..a0fe8b2
50 + params="${data_array[2]}"
51 + next="${data_array[5]}"
52 +
53 -+ echo "struct size_overflow_hash $struct_hash_name = {" >> "$header1"
54 ++ echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
55 +
56 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
57 + echo -en "\t.param\t= " >> "$header1"
58 @@ -110349,7 +110349,7 @@ index 0000000..a0fe8b2
59 +}
60 +
61 +create_headers () {
62 -+ echo "struct size_overflow_hash *size_overflow_hash[$n] = {" >> "$header1"
63 ++ echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
64 +}
65 +
66 +create_array_elements () {
67 @@ -113560,10 +113560,10 @@ index 0000000..42bbc4f
68 +_002415_hash acl_alloc_num 1-2 60778 _002415_hash NULL
69 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
70 new file mode 100644
71 -index 0000000..41e11e1
72 +index 0000000..e9310fa
73 --- /dev/null
74 +++ b/tools/gcc/size_overflow_plugin.c
75 -@@ -0,0 +1,1579 @@
76 +@@ -0,0 +1,1612 @@
77 +/*
78 + * Copyright 2011, 2012 by Emese Revfy <re.emese@×××××.com>
79 + * Licensed under the GPL v2, or (at your option) v3
80 @@ -113599,9 +113599,9 @@ index 0000000..41e11e1
81 +#include "cfgloop.h"
82 +
83 +struct size_overflow_hash {
84 -+ struct size_overflow_hash *next;
85 -+ const char *name;
86 -+ unsigned int param;
87 ++ const struct size_overflow_hash * const next;
88 ++ const char * const name;
89 ++ const unsigned int param;
90 +};
91 +
92 +#include "size_overflow_hash.h"
93 @@ -113624,15 +113624,16 @@ index 0000000..41e11e1
94 +int plugin_is_GPL_compatible;
95 +void debug_gimple_stmt(gimple gs);
96 +
97 -+static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
98 ++static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs);
99 +static tree report_size_overflow_decl;
100 -+static tree const_char_ptr_type_node;
101 ++static const_tree const_char_ptr_type_node;
102 +static unsigned int handle_function(void);
103 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before);
104 +static tree get_size_overflow_type(gimple stmt, tree node);
105 ++static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
106 +
107 +static struct plugin_info size_overflow_plugin_info = {
108 -+ .version = "20120815beta",
109 ++ .version = "20120820beta",
110 + .help = "no-size-overflow\tturn off size overflow checking\n",
111 +};
112 +
113 @@ -113685,8 +113686,8 @@ index 0000000..41e11e1
114 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
115 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
116 +
117 -+ const unsigned int m = 0x57559429;
118 -+ const unsigned int n = 0x5052acdb;
119 ++ unsigned int m = 0x57559429;
120 ++ unsigned int n = 0x5052acdb;
121 + const unsigned int *key4 = (const unsigned int *)key;
122 + unsigned int h = len;
123 + unsigned int k = len + seed + n;
124 @@ -113717,14 +113718,14 @@ index 0000000..41e11e1
125 + return fn ^ codes;
126 +}
127 +
128 -+static inline tree get_original_function_decl(tree fndecl)
129 ++static inline const_tree get_original_function_decl(const_tree fndecl)
130 +{
131 + if (DECL_ABSTRACT_ORIGIN(fndecl))
132 + return DECL_ABSTRACT_ORIGIN(fndecl);
133 + return fndecl;
134 +}
135 +
136 -+static inline gimple get_def_stmt(tree node)
137 ++static inline gimple get_def_stmt(const_tree node)
138 +{
139 + gcc_assert(node != NULL_TREE);
140 + gcc_assert(TREE_CODE(node) == SSA_NAME);
141 @@ -113776,9 +113777,10 @@ index 0000000..41e11e1
142 + return len;
143 +}
144 +
145 -+static unsigned int get_function_decl(tree fndecl, unsigned char *tree_codes)
146 ++static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
147 +{
148 -+ tree arg, result, type = TREE_TYPE(fndecl);
149 ++ tree arg;
150 ++ const_tree result, type = TREE_TYPE(fndecl);
151 + enum tree_code code = TREE_CODE(type);
152 + size_t len = 0;
153 +
154 @@ -113807,10 +113809,10 @@ index 0000000..41e11e1
155 + return len;
156 +}
157 +
158 -+static struct size_overflow_hash *get_function_hash(tree fndecl)
159 ++static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
160 +{
161 + unsigned int hash;
162 -+ struct size_overflow_hash *entry;
163 ++ const struct size_overflow_hash *entry;
164 + unsigned char tree_codes[CODES_LIMIT];
165 + size_t len;
166 + const char *func_name = NAME(fndecl);
167 @@ -113831,9 +113833,9 @@ index 0000000..41e11e1
168 + return NULL;
169 +}
170 +
171 -+static void check_arg_type(tree var)
172 ++static void check_arg_type(const_tree arg)
173 +{
174 -+ tree type = TREE_TYPE(var);
175 ++ const_tree type = TREE_TYPE(arg);
176 + enum tree_code code = TREE_CODE(type);
177 +
178 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
179 @@ -113841,7 +113843,7 @@ index 0000000..41e11e1
180 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
181 +}
182 +
183 -+static int find_arg_number(tree arg, tree func)
184 ++static int find_arg_number(const_tree arg, const_tree func)
185 +{
186 + tree var;
187 + bool match = false;
188 @@ -113867,7 +113869,7 @@ index 0000000..41e11e1
189 + return argnum;
190 +}
191 +
192 -+static void print_missing_msg(tree func, unsigned int argnum)
193 ++static void print_missing_msg(const_tree func, unsigned int argnum)
194 +{
195 + unsigned int new_hash;
196 + size_t len;
197 @@ -113880,16 +113882,15 @@ index 0000000..41e11e1
198 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
199 +}
200 +
201 -+static void check_missing_attribute(tree arg)
202 ++static void check_missing_attribute(const_tree arg)
203 +{
204 -+ tree type, func = get_original_function_decl(current_function_decl);
205 ++ const_tree type = TREE_TYPE(arg);
206 ++ const_tree func = get_original_function_decl(current_function_decl);
207 + unsigned int argnum;
208 -+ struct size_overflow_hash *hash;
209 ++ const struct size_overflow_hash *hash;
210 +
211 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
212 +
213 -+ type = TREE_TYPE(arg);
214 -+
215 + if (TREE_CODE(type) == POINTER_TYPE)
216 + return;
217 +
218 @@ -113930,9 +113931,9 @@ index 0000000..41e11e1
219 + return assign;
220 +}
221 +
222 -+static bool is_bool(tree node)
223 ++static bool is_bool(const_tree node)
224 +{
225 -+ tree type;
226 ++ const_tree type;
227 +
228 + if (node == NULL_TREE)
229 + return false;
230 @@ -113956,26 +113957,25 @@ index 0000000..41e11e1
231 + return fold_convert(type, var);
232 +}
233 +
234 -+static gimple build_cast_stmt(tree type, tree var, tree new_var, gimple_stmt_iterator *gsi, bool before)
235 ++static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
236 +{
237 + gimple assign;
238 -+ location_t loc;
239 +
240 -+ gcc_assert(type != NULL_TREE && var != NULL_TREE);
241 ++ gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
242 + if (gsi_end_p(*gsi) && before == BEFORE_STMT)
243 + gcc_unreachable();
244 +
245 -+ if (new_var == CREATE_NEW_VAR)
246 -+ new_var = create_new_var(type);
247 ++ if (lhs == CREATE_NEW_VAR)
248 ++ lhs = create_new_var(dst_type);
249 +
250 -+ assign = gimple_build_assign(new_var, cast_a_tree(type, var));
251 ++ assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
252 +
253 + if (!gsi_end_p(*gsi)) {
254 -+ loc = gimple_location(gsi_stmt(*gsi));
255 ++ location_t loc = gimple_location(gsi_stmt(*gsi));
256 + gimple_set_location(assign, loc);
257 + }
258 +
259 -+ gimple_set_lhs(assign, make_ssa_name(new_var, assign));
260 ++ gimple_set_lhs(assign, make_ssa_name(lhs, assign));
261 +
262 + if (before)
263 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
264 @@ -113989,7 +113989,7 @@ index 0000000..41e11e1
265 +
266 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
267 +{
268 -+ gimple assign;
269 ++ const_gimple assign;
270 + gimple_stmt_iterator gsi;
271 +
272 + if (new_rhs1 == NULL_TREE)
273 @@ -114003,9 +114003,25 @@ index 0000000..41e11e1
274 + return new_rhs1;
275 +}
276 +
277 ++static tree follow_overflow_type_and_dup(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree node, tree new_rhs1, tree new_rhs2, tree new_rhs3)
278 ++{
279 ++ tree size_overflow_type = get_size_overflow_type(stmt, node);
280 ++
281 ++ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
282 ++
283 ++ if (new_rhs2 != NULL_TREE)
284 ++ new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
285 ++
286 ++ if (new_rhs3 != NULL_TREE)
287 ++ new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
288 ++
289 ++ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
290 ++}
291 ++
292 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
293 +{
294 -+ tree oldstmt_rhs1, size_overflow_type, lhs;
295 ++ const_tree oldstmt_rhs1;
296 ++ tree size_overflow_type, lhs;
297 + enum tree_code code;
298 + gimple stmt;
299 + gimple_stmt_iterator gsi;
300 @@ -114033,7 +114049,7 @@ index 0000000..41e11e1
301 + pointer_set_insert(visited, oldstmt);
302 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
303 + basic_block next_bb, cur_bb;
304 -+ edge e;
305 ++ const_edge e;
306 +
307 + gcc_assert(before == false);
308 + gcc_assert(stmt_can_throw_internal(oldstmt));
309 @@ -114063,9 +114079,9 @@ index 0000000..41e11e1
310 +
311 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
312 +{
313 -+ tree new_var, lhs = gimple_get_lhs(oldstmt);
314 + gimple stmt;
315 + gimple_stmt_iterator gsi;
316 ++ tree new_var, lhs = gimple_get_lhs(oldstmt);
317 +
318 + if (!*potentionally_overflowed)
319 + return NULL_TREE;
320 @@ -114118,7 +114134,7 @@ index 0000000..41e11e1
321 + return gimple_get_lhs(stmt);
322 +}
323 +
324 -+static gimple overflow_create_phi_node(gimple oldstmt, tree var)
325 ++static gimple overflow_create_phi_node(gimple oldstmt, tree result)
326 +{
327 + basic_block bb;
328 + gimple phi;
329 @@ -114126,7 +114142,7 @@ index 0000000..41e11e1
330 +
331 + bb = gsi_bb(gsi);
332 +
333 -+ phi = create_phi_node(var, bb);
334 ++ phi = create_phi_node(result, bb);
335 + gsi = gsi_last(phi_nodes(bb));
336 + gsi_remove(&gsi, false);
337 +
338 @@ -114150,7 +114166,7 @@ index 0000000..41e11e1
339 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
340 +{
341 + basic_block bb;
342 -+ gimple newstmt;
343 ++ const_gimple newstmt;
344 + gimple_stmt_iterator gsi;
345 + bool before = BEFORE_STMT;
346 +
347 @@ -114172,7 +114188,7 @@ index 0000000..41e11e1
348 + return gimple_get_lhs(newstmt);
349 +}
350 +
351 -+static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
352 ++static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
353 +{
354 + gimple newstmt;
355 + gimple_stmt_iterator gsi;
356 @@ -114209,7 +114225,7 @@ index 0000000..41e11e1
357 +
358 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree size_overflow_type, tree arg, tree new_var)
359 +{
360 -+ gimple newstmt;
361 ++ const_gimple newstmt;
362 + tree new_rhs;
363 +
364 + new_rhs = expand(visited, potentionally_overflowed, arg);
365 @@ -114222,27 +114238,28 @@ index 0000000..41e11e1
366 + return gimple_get_lhs(newstmt);
367 +}
368 +
369 -+static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
370 ++static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, tree orig_result)
371 +{
372 -+ gimple phi, oldstmt = get_def_stmt(var);
373 -+ tree new_var, size_overflow_type;
374 -+ unsigned int i, n = gimple_phi_num_args(oldstmt);
375 ++ gimple phi, oldstmt = get_def_stmt(orig_result);
376 ++ tree new_result, size_overflow_type;
377 ++ unsigned int i;
378 ++ unsigned int n = gimple_phi_num_args(oldstmt);
379 +
380 -+ size_overflow_type = get_size_overflow_type(oldstmt, var);
381 ++ size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
382 +
383 -+ new_var = create_new_var(size_overflow_type);
384 ++ new_result = create_new_var(size_overflow_type);
385 +
386 + pointer_set_insert(visited, oldstmt);
387 -+ phi = overflow_create_phi_node(oldstmt, new_var);
388 ++ phi = overflow_create_phi_node(oldstmt, new_result);
389 + for (i = 0; i < n; i++) {
390 + tree arg, lhs;
391 +
392 + arg = gimple_phi_arg_def(oldstmt, i);
393 + if (is_gimple_constant(arg))
394 + arg = cast_a_tree(size_overflow_type, arg);
395 -+ lhs = build_new_phi_arg(visited, potentionally_overflowed, size_overflow_type, arg, new_var);
396 ++ lhs = build_new_phi_arg(visited, potentionally_overflowed, size_overflow_type, arg, new_result);
397 + if (lhs == NULL_TREE)
398 -+ lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_var, i);
399 ++ lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
400 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
401 + }
402 +
403 @@ -114250,9 +114267,9 @@ index 0000000..41e11e1
404 + return gimple_phi_result(phi);
405 +}
406 +
407 -+static tree change_assign_rhs(gimple stmt, tree orig_rhs, tree new_rhs)
408 ++static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
409 +{
410 -+ gimple assign;
411 ++ const_gimple assign;
412 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
413 + tree origtype = TREE_TYPE(orig_rhs);
414 +
415 @@ -114265,18 +114282,18 @@ index 0000000..41e11e1
416 +static void change_rhs1(gimple stmt, tree new_rhs1)
417 +{
418 + tree assign_rhs;
419 -+ tree rhs = gimple_assign_rhs1(stmt);
420 ++ const_tree rhs = gimple_assign_rhs1(stmt);
421 +
422 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
423 + gimple_assign_set_rhs1(stmt, assign_rhs);
424 + update_stmt(stmt);
425 +}
426 +
427 -+static bool check_mode_type(gimple stmt)
428 ++static bool check_mode_type(const_gimple stmt)
429 +{
430 -+ tree lhs = gimple_get_lhs(stmt);
431 -+ tree lhs_type = TREE_TYPE(lhs);
432 -+ tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
433 ++ const_tree lhs = gimple_get_lhs(stmt);
434 ++ const_tree lhs_type = TREE_TYPE(lhs);
435 ++ const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
436 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
437 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
438 +
439 @@ -114289,13 +114306,13 @@ index 0000000..41e11e1
440 + return true;
441 +}
442 +
443 -+static bool check_undefined_integer_operation(gimple stmt)
444 ++static bool check_undefined_integer_operation(const_gimple stmt)
445 +{
446 -+ gimple def_stmt;
447 -+ tree lhs = gimple_get_lhs(stmt);
448 -+ tree rhs1 = gimple_assign_rhs1(stmt);
449 -+ tree rhs1_type = TREE_TYPE(rhs1);
450 -+ tree lhs_type = TREE_TYPE(lhs);
451 ++ const_gimple def_stmt;
452 ++ const_tree lhs = gimple_get_lhs(stmt);
453 ++ const_tree rhs1 = gimple_assign_rhs1(stmt);
454 ++ const_tree rhs1_type = TREE_TYPE(rhs1);
455 ++ const_tree lhs_type = TREE_TYPE(lhs);
456 +
457 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
458 + return false;
459 @@ -114309,9 +114326,9 @@ index 0000000..41e11e1
460 + return true;
461 +}
462 +
463 -+static bool is_a_cast_and_const_overflow(tree no_const_rhs)
464 ++static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
465 +{
466 -+ tree rhs1, lhs, rhs1_type, lhs_type;
467 ++ const_tree rhs1, lhs, rhs1_type, lhs_type;
468 + enum machine_mode lhs_mode, rhs_mode;
469 + gimple def_stmt = get_def_stmt(no_const_rhs);
470 +
471 @@ -114334,8 +114351,8 @@ index 0000000..41e11e1
472 +{
473 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
474 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
475 -+ tree rhs1_type = TREE_TYPE(rhs1);
476 -+ tree lhs_type = TREE_TYPE(lhs);
477 ++ const_tree rhs1_type = TREE_TYPE(rhs1);
478 ++ const_tree lhs_type = TREE_TYPE(lhs);
479 +
480 + *potentionally_overflowed = true;
481 +
482 @@ -114347,23 +114364,18 @@ index 0000000..41e11e1
483 + if (gimple_plf(stmt, MY_STMT))
484 + return lhs;
485 +
486 -+ if (gimple_plf(stmt, NO_CAST_CHECK)) {
487 -+ size_overflow_type = get_size_overflow_type(stmt, rhs1);
488 -+ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
489 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
490 -+ }
491 ++ if (gimple_plf(stmt, NO_CAST_CHECK))
492 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
493 +
494 -+ if (!gimple_assign_cast_p(stmt)) {
495 -+ size_overflow_type = get_size_overflow_type(stmt, lhs);
496 ++ if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
497 ++ size_overflow_type = get_size_overflow_type(stmt, rhs1);
498 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
499 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
500 ++ check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, potentionally_overflowed, BEFORE_STMT);
501 ++ return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
502 + }
503 +
504 -+ if (check_undefined_integer_operation(stmt)) {
505 -+ size_overflow_type = get_size_overflow_type(stmt, lhs);
506 -+ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
507 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
508 -+ }
509 ++ if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
510 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
511 +
512 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
513 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
514 @@ -114432,7 +114444,7 @@ index 0000000..41e11e1
515 +static tree create_string_param(tree string)
516 +{
517 + tree i_type, a_type;
518 -+ int length = TREE_STRING_LENGTH(string);
519 ++ const int length = TREE_STRING_LENGTH(string);
520 +
521 + gcc_assert(length > 0);
522 +
523 @@ -114446,12 +114458,14 @@ index 0000000..41e11e1
524 + return build1(ADDR_EXPR, ptr_type_node, string);
525 +}
526 +
527 -+static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg, bool min)
528 ++static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
529 +{
530 -+ gimple func_stmt, def_stmt;
531 -+ tree current_func, loc_file, loc_line, ssa_name;
532 ++ gimple func_stmt;
533 ++ const_gimple def_stmt;
534 ++ const_tree loc_line;
535 ++ tree loc_file, ssa_name, current_func;
536 + expanded_location xloc;
537 -+ char ssa_name_buf[100];
538 ++ char ssa_name_buf[256];
539 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
540 +
541 + def_stmt = get_def_stmt(arg);
542 @@ -114471,8 +114485,8 @@ index 0000000..41e11e1
543 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
544 + current_func = create_string_param(current_func);
545 +
546 -+ snprintf(ssa_name_buf, sizeof(ssa_name_buf), "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
547 -+ ssa_name = build_string(sizeof(ssa_name_buf), ssa_name_buf);
548 ++ snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
549 ++ ssa_name = build_string(256, ssa_name_buf);
550 + ssa_name = create_string_param(ssa_name);
551 +
552 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
553 @@ -114481,7 +114495,7 @@ index 0000000..41e11e1
554 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
555 +}
556 +
557 -+static void __unused print_the_code_insertions(gimple stmt)
558 ++static void __unused print_the_code_insertions(const_gimple stmt)
559 +{
560 + location_t loc = gimple_location(stmt);
561 +
562 @@ -114529,7 +114543,9 @@ index 0000000..41e11e1
563 +
564 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before)
565 +{
566 -+ tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min, rhs_type = TREE_TYPE(rhs);
567 ++ const_tree rhs_type = TREE_TYPE(rhs);
568 ++ tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
569 ++
570 + gcc_assert(rhs_type != NULL_TREE);
571 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
572 +
573 @@ -114551,27 +114567,27 @@ index 0000000..41e11e1
574 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
575 +}
576 +
577 -+static tree get_handle_const_assign_size_overflow_type(gimple def_stmt, tree var_rhs)
578 ++static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
579 +{
580 -+ gimple var_rhs_def_stmt;
581 ++ gimple change_rhs_def_stmt;
582 + tree lhs = gimple_get_lhs(def_stmt);
583 + tree lhs_type = TREE_TYPE(lhs);
584 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
585 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
586 +
587 -+ if (var_rhs == NULL_TREE)
588 ++ if (change_rhs == NULL_TREE)
589 + return get_size_overflow_type(def_stmt, lhs);
590 +
591 -+ var_rhs_def_stmt = get_def_stmt(var_rhs);
592 ++ change_rhs_def_stmt = get_def_stmt(change_rhs);
593 +
594 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
595 -+ return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
596 ++ return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
597 +
598 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
599 -+ return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
600 ++ return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
601 +
602 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
603 -+ return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
604 ++ return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
605 +
606 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
607 + debug_gimple_stmt(def_stmt);
608 @@ -114581,45 +114597,16 @@ index 0000000..41e11e1
609 + return get_size_overflow_type(def_stmt, lhs);
610 +}
611 +
612 -+static tree handle_const_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple def_stmt, tree var_rhs, tree new_rhs1, tree new_rhs2)
613 ++static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
614 +{
615 -+ tree new_rhs, size_overflow_type, orig_rhs;
616 -+ void (*gimple_assign_set_rhs)(gimple, tree);
617 -+ tree rhs1 = gimple_assign_rhs1(def_stmt);
618 -+ tree rhs2 = gimple_assign_rhs2(def_stmt);
619 -+ tree lhs = gimple_get_lhs(def_stmt);
620 -+
621 -+ if (var_rhs == NULL_TREE)
622 -+ return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
623 -+
624 -+ if (new_rhs2 == NULL_TREE) {
625 -+ size_overflow_type = get_handle_const_assign_size_overflow_type(def_stmt, new_rhs1);
626 -+ new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
627 -+ orig_rhs = rhs1;
628 -+ gimple_assign_set_rhs = &gimple_assign_set_rhs1;
629 -+ } else {
630 -+ size_overflow_type = get_handle_const_assign_size_overflow_type(def_stmt, new_rhs2);
631 -+ new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
632 -+ orig_rhs = rhs2;
633 -+ gimple_assign_set_rhs = &gimple_assign_set_rhs2;
634 -+ }
635 -+
636 -+ var_rhs = cast_to_new_size_overflow_type(def_stmt, var_rhs, size_overflow_type, BEFORE_STMT);
637 -+
638 -+ if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
639 -+ return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
640 -+
641 -+ if (!is_a_cast_and_const_overflow(orig_rhs))
642 -+ check_size_overflow(def_stmt, size_overflow_type, var_rhs, orig_rhs, potentionally_overflowed, BEFORE_STMT);
643 -+
644 -+ new_rhs = change_assign_rhs(def_stmt, orig_rhs, var_rhs);
645 -+ gimple_assign_set_rhs(def_stmt, new_rhs);
646 -+ update_stmt(def_stmt);
647 -+
648 -+ return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
649 ++ if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
650 ++ return false;
651 ++ if (!is_gimple_constant(rhs))
652 ++ return false;
653 ++ return true;
654 +}
655 +
656 -+static tree get_cast_def_stmt_rhs(tree new_rhs)
657 ++static tree get_cast_def_stmt_rhs(const_tree new_rhs)
658 +{
659 + gimple def_stmt;
660 +
661 @@ -114633,7 +114620,8 @@ index 0000000..41e11e1
662 +static tree cast_to_int_TI_type_and_check(bool *potentionally_overflowed, gimple stmt, tree new_rhs)
663 +{
664 + gimple_stmt_iterator gsi;
665 -+ gimple cast_stmt, def_stmt;
666 ++ const_gimple cast_stmt;
667 ++ gimple def_stmt;
668 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
669 +
670 + if (mode != TImode && mode != DImode) {
671 @@ -114660,13 +114648,13 @@ index 0000000..41e11e1
672 + return new_rhs;
673 +}
674 +
675 -+static bool is_an_integer_trunction(gimple stmt)
676 ++static bool is_an_integer_trunction(const_gimple stmt)
677 +{
678 + gimple rhs1_def_stmt, rhs2_def_stmt;
679 -+ tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
680 ++ const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
681 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
682 -+ tree rhs1 = gimple_assign_rhs1(stmt);
683 -+ tree rhs2 = gimple_assign_rhs2(stmt);
684 ++ const_tree rhs1 = gimple_assign_rhs1(stmt);
685 ++ const_tree rhs2 = gimple_assign_rhs2(stmt);
686 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
687 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
688 +
689 @@ -114697,7 +114685,7 @@ index 0000000..41e11e1
690 +
691 +static tree handle_integer_truncation(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
692 +{
693 -+ tree new_rhs1, new_rhs2, size_overflow_type;
694 ++ tree new_rhs1, new_rhs2;
695 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
696 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
697 + gimple assign, stmt = get_def_stmt(lhs);
698 @@ -114725,15 +114713,64 @@ index 0000000..41e11e1
699 + new_lhs = gimple_get_lhs(assign);
700 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, potentionally_overflowed, AFTER_STMT);
701 +
702 -+ size_overflow_type = get_size_overflow_type(stmt, lhs);
703 -+ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
704 -+ new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
705 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
706 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
707 ++}
708 ++
709 ++static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
710 ++{
711 ++ const_gimple def_stmt;
712 ++
713 ++ if (TREE_CODE(rhs) != SSA_NAME)
714 ++ return false;
715 ++
716 ++ if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
717 ++ return false;
718 ++
719 ++ def_stmt = get_def_stmt(rhs);
720 ++ if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
721 ++ return false;
722 ++
723 ++ return true;
724 ++}
725 ++
726 ++static tree handle_intentional_overflow(struct pointer_set_t *visited, bool *potentionally_overflowed, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
727 ++{
728 ++ tree new_rhs, size_overflow_type, orig_rhs;
729 ++ void (*gimple_assign_set_rhs)(gimple, tree);
730 ++ tree rhs1 = gimple_assign_rhs1(stmt);
731 ++ tree rhs2 = gimple_assign_rhs2(stmt);
732 ++ tree lhs = gimple_get_lhs(stmt);
733 ++
734 ++ if (change_rhs == NULL_TREE)
735 ++ return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
736 ++
737 ++ if (new_rhs2 == NULL_TREE) {
738 ++ size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
739 ++ new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
740 ++ orig_rhs = rhs1;
741 ++ gimple_assign_set_rhs = &gimple_assign_set_rhs1;
742 ++ } else {
743 ++ size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
744 ++ new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
745 ++ orig_rhs = rhs2;
746 ++ gimple_assign_set_rhs = &gimple_assign_set_rhs2;
747 ++ }
748 ++
749 ++ change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
750 ++
751 ++ if (check_overflow)
752 ++ check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, potentionally_overflowed, BEFORE_STMT);
753 ++
754 ++ new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
755 ++ gimple_assign_set_rhs(stmt, new_rhs);
756 ++ update_stmt(stmt);
757 ++
758 ++ return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
759 +}
760 +
761 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
762 +{
763 -+ tree rhs1, rhs2, size_overflow_type, new_lhs;
764 ++ tree rhs1, rhs2, new_lhs;
765 + gimple def_stmt = get_def_stmt(lhs);
766 + tree new_rhs1 = NULL_TREE;
767 + tree new_rhs2 = NULL_TREE;
768 @@ -114771,18 +114808,17 @@ index 0000000..41e11e1
769 + if (TREE_CODE(rhs2) == SSA_NAME)
770 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
771 +
772 -+ if (is_gimple_constant(rhs2))
773 -+ return handle_const_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
774 -+
775 -+ if (is_gimple_constant(rhs1))
776 -+ return handle_const_assign(visited, potentionally_overflowed, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
777 -+
778 -+ size_overflow_type = get_size_overflow_type(def_stmt, lhs);
779 ++ if (is_a_neg_overflow(def_stmt, rhs2))
780 ++ return handle_intentional_overflow(visited, potentionally_overflowed, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
781 ++ if (is_a_neg_overflow(def_stmt, rhs1))
782 ++ return handle_intentional_overflow(visited, potentionally_overflowed, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
783 +
784 -+ new_rhs1 = cast_to_new_size_overflow_type(def_stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
785 -+ new_rhs2 = cast_to_new_size_overflow_type(def_stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
786 ++ if (is_a_constant_overflow(def_stmt, rhs2))
787 ++ return handle_intentional_overflow(visited, potentionally_overflowed, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
788 ++ if (is_a_constant_overflow(def_stmt, rhs1))
789 ++ return handle_intentional_overflow(visited, potentionally_overflowed, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
790 +
791 -+ return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
792 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
793 +}
794 +
795 +#if BUILDING_GCC_VERSION >= 4007
796 @@ -114795,14 +114831,14 @@ index 0000000..41e11e1
797 + return expand(visited, potentionally_overflowed, rhs);
798 +}
799 +
800 -+static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
801 ++static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
802 +{
803 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
804 -+ gimple def_stmt = get_def_stmt(var);
805 ++ gimple def_stmt = get_def_stmt(lhs);
806 +
807 + *potentionally_overflowed = true;
808 +
809 -+ size_overflow_type = get_size_overflow_type(def_stmt, var);
810 ++ size_overflow_type = get_size_overflow_type(def_stmt, lhs);
811 +
812 + rhs1 = gimple_assign_rhs1(def_stmt);
813 + rhs2 = gimple_assign_rhs2(def_stmt);
814 @@ -114811,11 +114847,7 @@ index 0000000..41e11e1
815 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs2);
816 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs3);
817 +
818 -+ new_rhs1 = cast_to_new_size_overflow_type(def_stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
819 -+ new_rhs2 = cast_to_new_size_overflow_type(def_stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
820 -+ new_rhs3 = cast_to_new_size_overflow_type(def_stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
821 -+
822 -+ return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
823 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
824 +}
825 +#endif
826 +
827 @@ -114850,7 +114882,7 @@ index 0000000..41e11e1
828 +
829 +static tree expand_visited(gimple def_stmt)
830 +{
831 -+ gimple next_stmt;
832 ++ const_gimple next_stmt;
833 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
834 +
835 + gsi_next(&gsi);
836 @@ -114868,51 +114900,51 @@ index 0000000..41e11e1
837 + }
838 +}
839 +
840 -+static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
841 ++static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
842 +{
843 + gimple def_stmt;
844 -+ enum tree_code code = TREE_CODE(TREE_TYPE(var));
845 ++ enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
846 +
847 -+ if (is_gimple_constant(var))
848 ++ if (is_gimple_constant(lhs))
849 + return NULL_TREE;
850 +
851 -+ if (TREE_CODE(var) == ADDR_EXPR)
852 ++ if (TREE_CODE(lhs) == ADDR_EXPR)
853 + return NULL_TREE;
854 +
855 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
856 +
857 -+ if (TREE_CODE(SSA_NAME_VAR(var)) == PARM_DECL)
858 -+ check_missing_attribute(var);
859 ++ if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
860 ++ check_missing_attribute(lhs);
861 +
862 -+ def_stmt = get_def_stmt(var);
863 ++ def_stmt = get_def_stmt(lhs);
864 +
865 + if (!def_stmt)
866 + return NULL_TREE;
867 +
868 + if (gimple_plf(def_stmt, MY_STMT))
869 -+ return var;
870 ++ return lhs;
871 +
872 + if (pointer_set_contains(visited, def_stmt))
873 + return expand_visited(def_stmt);
874 +
875 + switch (gimple_code(def_stmt)) {
876 + case GIMPLE_NOP:
877 -+ check_missing_attribute(var);
878 ++ check_missing_attribute(lhs);
879 + return NULL_TREE;
880 + case GIMPLE_PHI:
881 -+ return build_new_phi(visited, potentionally_overflowed, var);
882 ++ return build_new_phi(visited, potentionally_overflowed, lhs);
883 + case GIMPLE_CALL:
884 + case GIMPLE_ASM:
885 -+ return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
886 ++ return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
887 + case GIMPLE_ASSIGN:
888 + switch (gimple_num_ops(def_stmt)) {
889 + case 2:
890 -+ return handle_unary_ops(visited, potentionally_overflowed, var);
891 ++ return handle_unary_ops(visited, potentionally_overflowed, lhs);
892 + case 3:
893 -+ return handle_binary_ops(visited, potentionally_overflowed, var);
894 ++ return handle_binary_ops(visited, potentionally_overflowed, lhs);
895 +#if BUILDING_GCC_VERSION >= 4007
896 + case 4:
897 -+ return handle_ternary_ops(visited, potentionally_overflowed, var);
898 ++ return handle_ternary_ops(visited, potentionally_overflowed, lhs);
899 +#endif
900 + }
901 + default:
902 @@ -114922,9 +114954,9 @@ index 0000000..41e11e1
903 + }
904 +}
905 +
906 -+static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
907 ++static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
908 +{
909 -+ gimple assign;
910 ++ const_gimple assign;
911 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
912 + tree origtype = TREE_TYPE(origarg);
913 +
914 @@ -114936,10 +114968,11 @@ index 0000000..41e11e1
915 + update_stmt(stmt);
916 +}
917 +
918 -+static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
919 ++static tree get_function_arg(unsigned int argnum, const_gimple stmt, const_tree fndecl)
920 +{
921 + const char *origid;
922 -+ tree arg, origarg;
923 ++ tree arg;
924 ++ const_tree origarg;
925 +
926 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
927 + gcc_assert(gimple_call_num_args(stmt) > argnum);
928 @@ -114963,7 +114996,7 @@ index 0000000..41e11e1
929 + return NULL_TREE;
930 +}
931 +
932 -+static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
933 ++static void handle_function_arg(gimple stmt, const_tree fndecl, unsigned int argnum)
934 +{
935 + struct pointer_set_t *visited;
936 + tree arg, newarg;
937 @@ -114993,7 +115026,7 @@ index 0000000..41e11e1
938 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, &potentionally_overflowed, BEFORE_STMT);
939 +}
940 +
941 -+static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
942 ++static void handle_function_by_attribute(gimple stmt, const_tree attr, const_tree fndecl)
943 +{
944 + tree p = TREE_VALUE(attr);
945 + do {
946 @@ -115002,11 +115035,11 @@ index 0000000..41e11e1
947 + } while (p);
948 +}
949 +
950 -+static void handle_function_by_hash(gimple stmt, tree fndecl)
951 ++static void handle_function_by_hash(gimple stmt, const_tree fndecl)
952 +{
953 -+ tree orig_fndecl;
954 ++ const_tree orig_fndecl;
955 + unsigned int num;
956 -+ struct size_overflow_hash *hash;
957 ++ const struct size_overflow_hash *hash;
958 +
959 + orig_fndecl = get_original_function_decl(fndecl);
960 + hash = get_function_hash(orig_fndecl);
961 @@ -115043,7 +115076,7 @@ index 0000000..41e11e1
962 + next = bb->next_bb;
963 +
964 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
965 -+ tree fndecl, attr;
966 ++ const_tree fndecl, attr;
967 + gimple stmt = gsi_stmt(gsi);
968 +
969 + if (!(is_gimple_call(stmt)))
970
971 diff --git a/3.2.27/0000_README b/3.2.27/0000_README
972 index bf13cdb..f12c523 100644
973 --- a/3.2.27/0000_README
974 +++ b/3.2.27/0000_README
975 @@ -26,7 +26,7 @@ Patch: 1026_linux-3.2.27.patch
976 From: http://www.kernel.org
977 Desc: Linux 3.2.27
978
979 -Patch: 4420_grsecurity-2.9.1-3.2.27-201208151951.patch
980 +Patch: 4420_grsecurity-2.9.1-3.2.27-201208201521.patch
981 From: http://www.grsecurity.net
982 Desc: hardened-sources base patch from upstream grsecurity
983
984
985 diff --git a/3.2.27/4420_grsecurity-2.9.1-3.2.27-201208151951.patch b/3.2.27/4420_grsecurity-2.9.1-3.2.27-201208201521.patch
986 similarity index 99%
987 rename from 3.2.27/4420_grsecurity-2.9.1-3.2.27-201208151951.patch
988 rename to 3.2.27/4420_grsecurity-2.9.1-3.2.27-201208201521.patch
989 index 77e6914..7be4f7e 100644
990 --- a/3.2.27/4420_grsecurity-2.9.1-3.2.27-201208151951.patch
991 +++ b/3.2.27/4420_grsecurity-2.9.1-3.2.27-201208201521.patch
992 @@ -83258,7 +83258,7 @@ index 0000000..048d4ff
993 +}
994 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
995 new file mode 100644
996 -index 0000000..a0fe8b2
997 +index 0000000..68b646e
998 --- /dev/null
999 +++ b/tools/gcc/generate_size_overflow_hash.sh
1000 @@ -0,0 +1,94 @@
1001 @@ -83315,7 +83315,7 @@ index 0000000..a0fe8b2
1002 + params="${data_array[2]}"
1003 + next="${data_array[5]}"
1004 +
1005 -+ echo "struct size_overflow_hash $struct_hash_name = {" >> "$header1"
1006 ++ echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
1007 +
1008 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
1009 + echo -en "\t.param\t= " >> "$header1"
1010 @@ -83330,7 +83330,7 @@ index 0000000..a0fe8b2
1011 +}
1012 +
1013 +create_headers () {
1014 -+ echo "struct size_overflow_hash *size_overflow_hash[$n] = {" >> "$header1"
1015 ++ echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
1016 +}
1017 +
1018 +create_array_elements () {
1019 @@ -87207,10 +87207,10 @@ index 0000000..a898f84
1020 +_003150_hash acl_alloc_num 1-2 60778 _003150_hash NULL
1021 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
1022 new file mode 100644
1023 -index 0000000..41e11e1
1024 +index 0000000..e9310fa
1025 --- /dev/null
1026 +++ b/tools/gcc/size_overflow_plugin.c
1027 -@@ -0,0 +1,1579 @@
1028 +@@ -0,0 +1,1612 @@
1029 +/*
1030 + * Copyright 2011, 2012 by Emese Revfy <re.emese@×××××.com>
1031 + * Licensed under the GPL v2, or (at your option) v3
1032 @@ -87246,9 +87246,9 @@ index 0000000..41e11e1
1033 +#include "cfgloop.h"
1034 +
1035 +struct size_overflow_hash {
1036 -+ struct size_overflow_hash *next;
1037 -+ const char *name;
1038 -+ unsigned int param;
1039 ++ const struct size_overflow_hash * const next;
1040 ++ const char * const name;
1041 ++ const unsigned int param;
1042 +};
1043 +
1044 +#include "size_overflow_hash.h"
1045 @@ -87271,15 +87271,16 @@ index 0000000..41e11e1
1046 +int plugin_is_GPL_compatible;
1047 +void debug_gimple_stmt(gimple gs);
1048 +
1049 -+static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
1050 ++static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs);
1051 +static tree report_size_overflow_decl;
1052 -+static tree const_char_ptr_type_node;
1053 ++static const_tree const_char_ptr_type_node;
1054 +static unsigned int handle_function(void);
1055 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before);
1056 +static tree get_size_overflow_type(gimple stmt, tree node);
1057 ++static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
1058 +
1059 +static struct plugin_info size_overflow_plugin_info = {
1060 -+ .version = "20120815beta",
1061 ++ .version = "20120820beta",
1062 + .help = "no-size-overflow\tturn off size overflow checking\n",
1063 +};
1064 +
1065 @@ -87332,8 +87333,8 @@ index 0000000..41e11e1
1066 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
1067 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
1068 +
1069 -+ const unsigned int m = 0x57559429;
1070 -+ const unsigned int n = 0x5052acdb;
1071 ++ unsigned int m = 0x57559429;
1072 ++ unsigned int n = 0x5052acdb;
1073 + const unsigned int *key4 = (const unsigned int *)key;
1074 + unsigned int h = len;
1075 + unsigned int k = len + seed + n;
1076 @@ -87364,14 +87365,14 @@ index 0000000..41e11e1
1077 + return fn ^ codes;
1078 +}
1079 +
1080 -+static inline tree get_original_function_decl(tree fndecl)
1081 ++static inline const_tree get_original_function_decl(const_tree fndecl)
1082 +{
1083 + if (DECL_ABSTRACT_ORIGIN(fndecl))
1084 + return DECL_ABSTRACT_ORIGIN(fndecl);
1085 + return fndecl;
1086 +}
1087 +
1088 -+static inline gimple get_def_stmt(tree node)
1089 ++static inline gimple get_def_stmt(const_tree node)
1090 +{
1091 + gcc_assert(node != NULL_TREE);
1092 + gcc_assert(TREE_CODE(node) == SSA_NAME);
1093 @@ -87423,9 +87424,10 @@ index 0000000..41e11e1
1094 + return len;
1095 +}
1096 +
1097 -+static unsigned int get_function_decl(tree fndecl, unsigned char *tree_codes)
1098 ++static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
1099 +{
1100 -+ tree arg, result, type = TREE_TYPE(fndecl);
1101 ++ tree arg;
1102 ++ const_tree result, type = TREE_TYPE(fndecl);
1103 + enum tree_code code = TREE_CODE(type);
1104 + size_t len = 0;
1105 +
1106 @@ -87454,10 +87456,10 @@ index 0000000..41e11e1
1107 + return len;
1108 +}
1109 +
1110 -+static struct size_overflow_hash *get_function_hash(tree fndecl)
1111 ++static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
1112 +{
1113 + unsigned int hash;
1114 -+ struct size_overflow_hash *entry;
1115 ++ const struct size_overflow_hash *entry;
1116 + unsigned char tree_codes[CODES_LIMIT];
1117 + size_t len;
1118 + const char *func_name = NAME(fndecl);
1119 @@ -87478,9 +87480,9 @@ index 0000000..41e11e1
1120 + return NULL;
1121 +}
1122 +
1123 -+static void check_arg_type(tree var)
1124 ++static void check_arg_type(const_tree arg)
1125 +{
1126 -+ tree type = TREE_TYPE(var);
1127 ++ const_tree type = TREE_TYPE(arg);
1128 + enum tree_code code = TREE_CODE(type);
1129 +
1130 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
1131 @@ -87488,7 +87490,7 @@ index 0000000..41e11e1
1132 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
1133 +}
1134 +
1135 -+static int find_arg_number(tree arg, tree func)
1136 ++static int find_arg_number(const_tree arg, const_tree func)
1137 +{
1138 + tree var;
1139 + bool match = false;
1140 @@ -87514,7 +87516,7 @@ index 0000000..41e11e1
1141 + return argnum;
1142 +}
1143 +
1144 -+static void print_missing_msg(tree func, unsigned int argnum)
1145 ++static void print_missing_msg(const_tree func, unsigned int argnum)
1146 +{
1147 + unsigned int new_hash;
1148 + size_t len;
1149 @@ -87527,16 +87529,15 @@ index 0000000..41e11e1
1150 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
1151 +}
1152 +
1153 -+static void check_missing_attribute(tree arg)
1154 ++static void check_missing_attribute(const_tree arg)
1155 +{
1156 -+ tree type, func = get_original_function_decl(current_function_decl);
1157 ++ const_tree type = TREE_TYPE(arg);
1158 ++ const_tree func = get_original_function_decl(current_function_decl);
1159 + unsigned int argnum;
1160 -+ struct size_overflow_hash *hash;
1161 ++ const struct size_overflow_hash *hash;
1162 +
1163 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
1164 +
1165 -+ type = TREE_TYPE(arg);
1166 -+
1167 + if (TREE_CODE(type) == POINTER_TYPE)
1168 + return;
1169 +
1170 @@ -87577,9 +87578,9 @@ index 0000000..41e11e1
1171 + return assign;
1172 +}
1173 +
1174 -+static bool is_bool(tree node)
1175 ++static bool is_bool(const_tree node)
1176 +{
1177 -+ tree type;
1178 ++ const_tree type;
1179 +
1180 + if (node == NULL_TREE)
1181 + return false;
1182 @@ -87603,26 +87604,25 @@ index 0000000..41e11e1
1183 + return fold_convert(type, var);
1184 +}
1185 +
1186 -+static gimple build_cast_stmt(tree type, tree var, tree new_var, gimple_stmt_iterator *gsi, bool before)
1187 ++static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
1188 +{
1189 + gimple assign;
1190 -+ location_t loc;
1191 +
1192 -+ gcc_assert(type != NULL_TREE && var != NULL_TREE);
1193 ++ gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
1194 + if (gsi_end_p(*gsi) && before == BEFORE_STMT)
1195 + gcc_unreachable();
1196 +
1197 -+ if (new_var == CREATE_NEW_VAR)
1198 -+ new_var = create_new_var(type);
1199 ++ if (lhs == CREATE_NEW_VAR)
1200 ++ lhs = create_new_var(dst_type);
1201 +
1202 -+ assign = gimple_build_assign(new_var, cast_a_tree(type, var));
1203 ++ assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
1204 +
1205 + if (!gsi_end_p(*gsi)) {
1206 -+ loc = gimple_location(gsi_stmt(*gsi));
1207 ++ location_t loc = gimple_location(gsi_stmt(*gsi));
1208 + gimple_set_location(assign, loc);
1209 + }
1210 +
1211 -+ gimple_set_lhs(assign, make_ssa_name(new_var, assign));
1212 ++ gimple_set_lhs(assign, make_ssa_name(lhs, assign));
1213 +
1214 + if (before)
1215 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
1216 @@ -87636,7 +87636,7 @@ index 0000000..41e11e1
1217 +
1218 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
1219 +{
1220 -+ gimple assign;
1221 ++ const_gimple assign;
1222 + gimple_stmt_iterator gsi;
1223 +
1224 + if (new_rhs1 == NULL_TREE)
1225 @@ -87650,9 +87650,25 @@ index 0000000..41e11e1
1226 + return new_rhs1;
1227 +}
1228 +
1229 ++static tree follow_overflow_type_and_dup(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree node, tree new_rhs1, tree new_rhs2, tree new_rhs3)
1230 ++{
1231 ++ tree size_overflow_type = get_size_overflow_type(stmt, node);
1232 ++
1233 ++ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
1234 ++
1235 ++ if (new_rhs2 != NULL_TREE)
1236 ++ new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
1237 ++
1238 ++ if (new_rhs3 != NULL_TREE)
1239 ++ new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
1240 ++
1241 ++ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
1242 ++}
1243 ++
1244 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
1245 +{
1246 -+ tree oldstmt_rhs1, size_overflow_type, lhs;
1247 ++ const_tree oldstmt_rhs1;
1248 ++ tree size_overflow_type, lhs;
1249 + enum tree_code code;
1250 + gimple stmt;
1251 + gimple_stmt_iterator gsi;
1252 @@ -87680,7 +87696,7 @@ index 0000000..41e11e1
1253 + pointer_set_insert(visited, oldstmt);
1254 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
1255 + basic_block next_bb, cur_bb;
1256 -+ edge e;
1257 ++ const_edge e;
1258 +
1259 + gcc_assert(before == false);
1260 + gcc_assert(stmt_can_throw_internal(oldstmt));
1261 @@ -87710,9 +87726,9 @@ index 0000000..41e11e1
1262 +
1263 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
1264 +{
1265 -+ tree new_var, lhs = gimple_get_lhs(oldstmt);
1266 + gimple stmt;
1267 + gimple_stmt_iterator gsi;
1268 ++ tree new_var, lhs = gimple_get_lhs(oldstmt);
1269 +
1270 + if (!*potentionally_overflowed)
1271 + return NULL_TREE;
1272 @@ -87765,7 +87781,7 @@ index 0000000..41e11e1
1273 + return gimple_get_lhs(stmt);
1274 +}
1275 +
1276 -+static gimple overflow_create_phi_node(gimple oldstmt, tree var)
1277 ++static gimple overflow_create_phi_node(gimple oldstmt, tree result)
1278 +{
1279 + basic_block bb;
1280 + gimple phi;
1281 @@ -87773,7 +87789,7 @@ index 0000000..41e11e1
1282 +
1283 + bb = gsi_bb(gsi);
1284 +
1285 -+ phi = create_phi_node(var, bb);
1286 ++ phi = create_phi_node(result, bb);
1287 + gsi = gsi_last(phi_nodes(bb));
1288 + gsi_remove(&gsi, false);
1289 +
1290 @@ -87797,7 +87813,7 @@ index 0000000..41e11e1
1291 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
1292 +{
1293 + basic_block bb;
1294 -+ gimple newstmt;
1295 ++ const_gimple newstmt;
1296 + gimple_stmt_iterator gsi;
1297 + bool before = BEFORE_STMT;
1298 +
1299 @@ -87819,7 +87835,7 @@ index 0000000..41e11e1
1300 + return gimple_get_lhs(newstmt);
1301 +}
1302 +
1303 -+static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
1304 ++static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
1305 +{
1306 + gimple newstmt;
1307 + gimple_stmt_iterator gsi;
1308 @@ -87856,7 +87872,7 @@ index 0000000..41e11e1
1309 +
1310 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree size_overflow_type, tree arg, tree new_var)
1311 +{
1312 -+ gimple newstmt;
1313 ++ const_gimple newstmt;
1314 + tree new_rhs;
1315 +
1316 + new_rhs = expand(visited, potentionally_overflowed, arg);
1317 @@ -87869,27 +87885,28 @@ index 0000000..41e11e1
1318 + return gimple_get_lhs(newstmt);
1319 +}
1320 +
1321 -+static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
1322 ++static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, tree orig_result)
1323 +{
1324 -+ gimple phi, oldstmt = get_def_stmt(var);
1325 -+ tree new_var, size_overflow_type;
1326 -+ unsigned int i, n = gimple_phi_num_args(oldstmt);
1327 ++ gimple phi, oldstmt = get_def_stmt(orig_result);
1328 ++ tree new_result, size_overflow_type;
1329 ++ unsigned int i;
1330 ++ unsigned int n = gimple_phi_num_args(oldstmt);
1331 +
1332 -+ size_overflow_type = get_size_overflow_type(oldstmt, var);
1333 ++ size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
1334 +
1335 -+ new_var = create_new_var(size_overflow_type);
1336 ++ new_result = create_new_var(size_overflow_type);
1337 +
1338 + pointer_set_insert(visited, oldstmt);
1339 -+ phi = overflow_create_phi_node(oldstmt, new_var);
1340 ++ phi = overflow_create_phi_node(oldstmt, new_result);
1341 + for (i = 0; i < n; i++) {
1342 + tree arg, lhs;
1343 +
1344 + arg = gimple_phi_arg_def(oldstmt, i);
1345 + if (is_gimple_constant(arg))
1346 + arg = cast_a_tree(size_overflow_type, arg);
1347 -+ lhs = build_new_phi_arg(visited, potentionally_overflowed, size_overflow_type, arg, new_var);
1348 ++ lhs = build_new_phi_arg(visited, potentionally_overflowed, size_overflow_type, arg, new_result);
1349 + if (lhs == NULL_TREE)
1350 -+ lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_var, i);
1351 ++ lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
1352 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
1353 + }
1354 +
1355 @@ -87897,9 +87914,9 @@ index 0000000..41e11e1
1356 + return gimple_phi_result(phi);
1357 +}
1358 +
1359 -+static tree change_assign_rhs(gimple stmt, tree orig_rhs, tree new_rhs)
1360 ++static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
1361 +{
1362 -+ gimple assign;
1363 ++ const_gimple assign;
1364 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
1365 + tree origtype = TREE_TYPE(orig_rhs);
1366 +
1367 @@ -87912,18 +87929,18 @@ index 0000000..41e11e1
1368 +static void change_rhs1(gimple stmt, tree new_rhs1)
1369 +{
1370 + tree assign_rhs;
1371 -+ tree rhs = gimple_assign_rhs1(stmt);
1372 ++ const_tree rhs = gimple_assign_rhs1(stmt);
1373 +
1374 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
1375 + gimple_assign_set_rhs1(stmt, assign_rhs);
1376 + update_stmt(stmt);
1377 +}
1378 +
1379 -+static bool check_mode_type(gimple stmt)
1380 ++static bool check_mode_type(const_gimple stmt)
1381 +{
1382 -+ tree lhs = gimple_get_lhs(stmt);
1383 -+ tree lhs_type = TREE_TYPE(lhs);
1384 -+ tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
1385 ++ const_tree lhs = gimple_get_lhs(stmt);
1386 ++ const_tree lhs_type = TREE_TYPE(lhs);
1387 ++ const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
1388 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
1389 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
1390 +
1391 @@ -87936,13 +87953,13 @@ index 0000000..41e11e1
1392 + return true;
1393 +}
1394 +
1395 -+static bool check_undefined_integer_operation(gimple stmt)
1396 ++static bool check_undefined_integer_operation(const_gimple stmt)
1397 +{
1398 -+ gimple def_stmt;
1399 -+ tree lhs = gimple_get_lhs(stmt);
1400 -+ tree rhs1 = gimple_assign_rhs1(stmt);
1401 -+ tree rhs1_type = TREE_TYPE(rhs1);
1402 -+ tree lhs_type = TREE_TYPE(lhs);
1403 ++ const_gimple def_stmt;
1404 ++ const_tree lhs = gimple_get_lhs(stmt);
1405 ++ const_tree rhs1 = gimple_assign_rhs1(stmt);
1406 ++ const_tree rhs1_type = TREE_TYPE(rhs1);
1407 ++ const_tree lhs_type = TREE_TYPE(lhs);
1408 +
1409 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
1410 + return false;
1411 @@ -87956,9 +87973,9 @@ index 0000000..41e11e1
1412 + return true;
1413 +}
1414 +
1415 -+static bool is_a_cast_and_const_overflow(tree no_const_rhs)
1416 ++static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
1417 +{
1418 -+ tree rhs1, lhs, rhs1_type, lhs_type;
1419 ++ const_tree rhs1, lhs, rhs1_type, lhs_type;
1420 + enum machine_mode lhs_mode, rhs_mode;
1421 + gimple def_stmt = get_def_stmt(no_const_rhs);
1422 +
1423 @@ -87981,8 +87998,8 @@ index 0000000..41e11e1
1424 +{
1425 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
1426 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
1427 -+ tree rhs1_type = TREE_TYPE(rhs1);
1428 -+ tree lhs_type = TREE_TYPE(lhs);
1429 ++ const_tree rhs1_type = TREE_TYPE(rhs1);
1430 ++ const_tree lhs_type = TREE_TYPE(lhs);
1431 +
1432 + *potentionally_overflowed = true;
1433 +
1434 @@ -87994,23 +88011,18 @@ index 0000000..41e11e1
1435 + if (gimple_plf(stmt, MY_STMT))
1436 + return lhs;
1437 +
1438 -+ if (gimple_plf(stmt, NO_CAST_CHECK)) {
1439 -+ size_overflow_type = get_size_overflow_type(stmt, rhs1);
1440 -+ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
1441 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
1442 -+ }
1443 ++ if (gimple_plf(stmt, NO_CAST_CHECK))
1444 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
1445 +
1446 -+ if (!gimple_assign_cast_p(stmt)) {
1447 -+ size_overflow_type = get_size_overflow_type(stmt, lhs);
1448 ++ if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
1449 ++ size_overflow_type = get_size_overflow_type(stmt, rhs1);
1450 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
1451 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
1452 ++ check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, potentionally_overflowed, BEFORE_STMT);
1453 ++ return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
1454 + }
1455 +
1456 -+ if (check_undefined_integer_operation(stmt)) {
1457 -+ size_overflow_type = get_size_overflow_type(stmt, lhs);
1458 -+ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
1459 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
1460 -+ }
1461 ++ if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
1462 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
1463 +
1464 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
1465 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
1466 @@ -88079,7 +88091,7 @@ index 0000000..41e11e1
1467 +static tree create_string_param(tree string)
1468 +{
1469 + tree i_type, a_type;
1470 -+ int length = TREE_STRING_LENGTH(string);
1471 ++ const int length = TREE_STRING_LENGTH(string);
1472 +
1473 + gcc_assert(length > 0);
1474 +
1475 @@ -88093,12 +88105,14 @@ index 0000000..41e11e1
1476 + return build1(ADDR_EXPR, ptr_type_node, string);
1477 +}
1478 +
1479 -+static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg, bool min)
1480 ++static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
1481 +{
1482 -+ gimple func_stmt, def_stmt;
1483 -+ tree current_func, loc_file, loc_line, ssa_name;
1484 ++ gimple func_stmt;
1485 ++ const_gimple def_stmt;
1486 ++ const_tree loc_line;
1487 ++ tree loc_file, ssa_name, current_func;
1488 + expanded_location xloc;
1489 -+ char ssa_name_buf[100];
1490 ++ char ssa_name_buf[256];
1491 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
1492 +
1493 + def_stmt = get_def_stmt(arg);
1494 @@ -88118,8 +88132,8 @@ index 0000000..41e11e1
1495 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
1496 + current_func = create_string_param(current_func);
1497 +
1498 -+ snprintf(ssa_name_buf, sizeof(ssa_name_buf), "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
1499 -+ ssa_name = build_string(sizeof(ssa_name_buf), ssa_name_buf);
1500 ++ snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
1501 ++ ssa_name = build_string(256, ssa_name_buf);
1502 + ssa_name = create_string_param(ssa_name);
1503 +
1504 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
1505 @@ -88128,7 +88142,7 @@ index 0000000..41e11e1
1506 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
1507 +}
1508 +
1509 -+static void __unused print_the_code_insertions(gimple stmt)
1510 ++static void __unused print_the_code_insertions(const_gimple stmt)
1511 +{
1512 + location_t loc = gimple_location(stmt);
1513 +
1514 @@ -88176,7 +88190,9 @@ index 0000000..41e11e1
1515 +
1516 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before)
1517 +{
1518 -+ tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min, rhs_type = TREE_TYPE(rhs);
1519 ++ const_tree rhs_type = TREE_TYPE(rhs);
1520 ++ tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
1521 ++
1522 + gcc_assert(rhs_type != NULL_TREE);
1523 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
1524 +
1525 @@ -88198,27 +88214,27 @@ index 0000000..41e11e1
1526 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
1527 +}
1528 +
1529 -+static tree get_handle_const_assign_size_overflow_type(gimple def_stmt, tree var_rhs)
1530 ++static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
1531 +{
1532 -+ gimple var_rhs_def_stmt;
1533 ++ gimple change_rhs_def_stmt;
1534 + tree lhs = gimple_get_lhs(def_stmt);
1535 + tree lhs_type = TREE_TYPE(lhs);
1536 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
1537 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
1538 +
1539 -+ if (var_rhs == NULL_TREE)
1540 ++ if (change_rhs == NULL_TREE)
1541 + return get_size_overflow_type(def_stmt, lhs);
1542 +
1543 -+ var_rhs_def_stmt = get_def_stmt(var_rhs);
1544 ++ change_rhs_def_stmt = get_def_stmt(change_rhs);
1545 +
1546 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
1547 -+ return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
1548 ++ return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
1549 +
1550 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
1551 -+ return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
1552 ++ return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
1553 +
1554 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
1555 -+ return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
1556 ++ return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
1557 +
1558 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
1559 + debug_gimple_stmt(def_stmt);
1560 @@ -88228,45 +88244,16 @@ index 0000000..41e11e1
1561 + return get_size_overflow_type(def_stmt, lhs);
1562 +}
1563 +
1564 -+static tree handle_const_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple def_stmt, tree var_rhs, tree new_rhs1, tree new_rhs2)
1565 ++static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
1566 +{
1567 -+ tree new_rhs, size_overflow_type, orig_rhs;
1568 -+ void (*gimple_assign_set_rhs)(gimple, tree);
1569 -+ tree rhs1 = gimple_assign_rhs1(def_stmt);
1570 -+ tree rhs2 = gimple_assign_rhs2(def_stmt);
1571 -+ tree lhs = gimple_get_lhs(def_stmt);
1572 -+
1573 -+ if (var_rhs == NULL_TREE)
1574 -+ return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
1575 -+
1576 -+ if (new_rhs2 == NULL_TREE) {
1577 -+ size_overflow_type = get_handle_const_assign_size_overflow_type(def_stmt, new_rhs1);
1578 -+ new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
1579 -+ orig_rhs = rhs1;
1580 -+ gimple_assign_set_rhs = &gimple_assign_set_rhs1;
1581 -+ } else {
1582 -+ size_overflow_type = get_handle_const_assign_size_overflow_type(def_stmt, new_rhs2);
1583 -+ new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
1584 -+ orig_rhs = rhs2;
1585 -+ gimple_assign_set_rhs = &gimple_assign_set_rhs2;
1586 -+ }
1587 -+
1588 -+ var_rhs = cast_to_new_size_overflow_type(def_stmt, var_rhs, size_overflow_type, BEFORE_STMT);
1589 -+
1590 -+ if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
1591 -+ return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
1592 -+
1593 -+ if (!is_a_cast_and_const_overflow(orig_rhs))
1594 -+ check_size_overflow(def_stmt, size_overflow_type, var_rhs, orig_rhs, potentionally_overflowed, BEFORE_STMT);
1595 -+
1596 -+ new_rhs = change_assign_rhs(def_stmt, orig_rhs, var_rhs);
1597 -+ gimple_assign_set_rhs(def_stmt, new_rhs);
1598 -+ update_stmt(def_stmt);
1599 -+
1600 -+ return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
1601 ++ if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
1602 ++ return false;
1603 ++ if (!is_gimple_constant(rhs))
1604 ++ return false;
1605 ++ return true;
1606 +}
1607 +
1608 -+static tree get_cast_def_stmt_rhs(tree new_rhs)
1609 ++static tree get_cast_def_stmt_rhs(const_tree new_rhs)
1610 +{
1611 + gimple def_stmt;
1612 +
1613 @@ -88280,7 +88267,8 @@ index 0000000..41e11e1
1614 +static tree cast_to_int_TI_type_and_check(bool *potentionally_overflowed, gimple stmt, tree new_rhs)
1615 +{
1616 + gimple_stmt_iterator gsi;
1617 -+ gimple cast_stmt, def_stmt;
1618 ++ const_gimple cast_stmt;
1619 ++ gimple def_stmt;
1620 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
1621 +
1622 + if (mode != TImode && mode != DImode) {
1623 @@ -88307,13 +88295,13 @@ index 0000000..41e11e1
1624 + return new_rhs;
1625 +}
1626 +
1627 -+static bool is_an_integer_trunction(gimple stmt)
1628 ++static bool is_an_integer_trunction(const_gimple stmt)
1629 +{
1630 + gimple rhs1_def_stmt, rhs2_def_stmt;
1631 -+ tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
1632 ++ const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
1633 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
1634 -+ tree rhs1 = gimple_assign_rhs1(stmt);
1635 -+ tree rhs2 = gimple_assign_rhs2(stmt);
1636 ++ const_tree rhs1 = gimple_assign_rhs1(stmt);
1637 ++ const_tree rhs2 = gimple_assign_rhs2(stmt);
1638 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
1639 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
1640 +
1641 @@ -88344,7 +88332,7 @@ index 0000000..41e11e1
1642 +
1643 +static tree handle_integer_truncation(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
1644 +{
1645 -+ tree new_rhs1, new_rhs2, size_overflow_type;
1646 ++ tree new_rhs1, new_rhs2;
1647 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
1648 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
1649 + gimple assign, stmt = get_def_stmt(lhs);
1650 @@ -88372,15 +88360,64 @@ index 0000000..41e11e1
1651 + new_lhs = gimple_get_lhs(assign);
1652 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, potentionally_overflowed, AFTER_STMT);
1653 +
1654 -+ size_overflow_type = get_size_overflow_type(stmt, lhs);
1655 -+ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
1656 -+ new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
1657 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
1658 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
1659 ++}
1660 ++
1661 ++static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
1662 ++{
1663 ++ const_gimple def_stmt;
1664 ++
1665 ++ if (TREE_CODE(rhs) != SSA_NAME)
1666 ++ return false;
1667 ++
1668 ++ if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
1669 ++ return false;
1670 ++
1671 ++ def_stmt = get_def_stmt(rhs);
1672 ++ if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
1673 ++ return false;
1674 ++
1675 ++ return true;
1676 ++}
1677 ++
1678 ++static tree handle_intentional_overflow(struct pointer_set_t *visited, bool *potentionally_overflowed, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
1679 ++{
1680 ++ tree new_rhs, size_overflow_type, orig_rhs;
1681 ++ void (*gimple_assign_set_rhs)(gimple, tree);
1682 ++ tree rhs1 = gimple_assign_rhs1(stmt);
1683 ++ tree rhs2 = gimple_assign_rhs2(stmt);
1684 ++ tree lhs = gimple_get_lhs(stmt);
1685 ++
1686 ++ if (change_rhs == NULL_TREE)
1687 ++ return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
1688 ++
1689 ++ if (new_rhs2 == NULL_TREE) {
1690 ++ size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
1691 ++ new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
1692 ++ orig_rhs = rhs1;
1693 ++ gimple_assign_set_rhs = &gimple_assign_set_rhs1;
1694 ++ } else {
1695 ++ size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
1696 ++ new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
1697 ++ orig_rhs = rhs2;
1698 ++ gimple_assign_set_rhs = &gimple_assign_set_rhs2;
1699 ++ }
1700 ++
1701 ++ change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
1702 ++
1703 ++ if (check_overflow)
1704 ++ check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, potentionally_overflowed, BEFORE_STMT);
1705 ++
1706 ++ new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
1707 ++ gimple_assign_set_rhs(stmt, new_rhs);
1708 ++ update_stmt(stmt);
1709 ++
1710 ++ return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
1711 +}
1712 +
1713 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
1714 +{
1715 -+ tree rhs1, rhs2, size_overflow_type, new_lhs;
1716 ++ tree rhs1, rhs2, new_lhs;
1717 + gimple def_stmt = get_def_stmt(lhs);
1718 + tree new_rhs1 = NULL_TREE;
1719 + tree new_rhs2 = NULL_TREE;
1720 @@ -88418,18 +88455,17 @@ index 0000000..41e11e1
1721 + if (TREE_CODE(rhs2) == SSA_NAME)
1722 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
1723 +
1724 -+ if (is_gimple_constant(rhs2))
1725 -+ return handle_const_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
1726 -+
1727 -+ if (is_gimple_constant(rhs1))
1728 -+ return handle_const_assign(visited, potentionally_overflowed, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
1729 -+
1730 -+ size_overflow_type = get_size_overflow_type(def_stmt, lhs);
1731 ++ if (is_a_neg_overflow(def_stmt, rhs2))
1732 ++ return handle_intentional_overflow(visited, potentionally_overflowed, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
1733 ++ if (is_a_neg_overflow(def_stmt, rhs1))
1734 ++ return handle_intentional_overflow(visited, potentionally_overflowed, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
1735 +
1736 -+ new_rhs1 = cast_to_new_size_overflow_type(def_stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
1737 -+ new_rhs2 = cast_to_new_size_overflow_type(def_stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
1738 ++ if (is_a_constant_overflow(def_stmt, rhs2))
1739 ++ return handle_intentional_overflow(visited, potentionally_overflowed, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
1740 ++ if (is_a_constant_overflow(def_stmt, rhs1))
1741 ++ return handle_intentional_overflow(visited, potentionally_overflowed, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
1742 +
1743 -+ return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
1744 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
1745 +}
1746 +
1747 +#if BUILDING_GCC_VERSION >= 4007
1748 @@ -88442,14 +88478,14 @@ index 0000000..41e11e1
1749 + return expand(visited, potentionally_overflowed, rhs);
1750 +}
1751 +
1752 -+static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
1753 ++static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
1754 +{
1755 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
1756 -+ gimple def_stmt = get_def_stmt(var);
1757 ++ gimple def_stmt = get_def_stmt(lhs);
1758 +
1759 + *potentionally_overflowed = true;
1760 +
1761 -+ size_overflow_type = get_size_overflow_type(def_stmt, var);
1762 ++ size_overflow_type = get_size_overflow_type(def_stmt, lhs);
1763 +
1764 + rhs1 = gimple_assign_rhs1(def_stmt);
1765 + rhs2 = gimple_assign_rhs2(def_stmt);
1766 @@ -88458,11 +88494,7 @@ index 0000000..41e11e1
1767 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs2);
1768 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs3);
1769 +
1770 -+ new_rhs1 = cast_to_new_size_overflow_type(def_stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
1771 -+ new_rhs2 = cast_to_new_size_overflow_type(def_stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
1772 -+ new_rhs3 = cast_to_new_size_overflow_type(def_stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
1773 -+
1774 -+ return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
1775 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
1776 +}
1777 +#endif
1778 +
1779 @@ -88497,7 +88529,7 @@ index 0000000..41e11e1
1780 +
1781 +static tree expand_visited(gimple def_stmt)
1782 +{
1783 -+ gimple next_stmt;
1784 ++ const_gimple next_stmt;
1785 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
1786 +
1787 + gsi_next(&gsi);
1788 @@ -88515,51 +88547,51 @@ index 0000000..41e11e1
1789 + }
1790 +}
1791 +
1792 -+static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
1793 ++static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
1794 +{
1795 + gimple def_stmt;
1796 -+ enum tree_code code = TREE_CODE(TREE_TYPE(var));
1797 ++ enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
1798 +
1799 -+ if (is_gimple_constant(var))
1800 ++ if (is_gimple_constant(lhs))
1801 + return NULL_TREE;
1802 +
1803 -+ if (TREE_CODE(var) == ADDR_EXPR)
1804 ++ if (TREE_CODE(lhs) == ADDR_EXPR)
1805 + return NULL_TREE;
1806 +
1807 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
1808 +
1809 -+ if (TREE_CODE(SSA_NAME_VAR(var)) == PARM_DECL)
1810 -+ check_missing_attribute(var);
1811 ++ if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
1812 ++ check_missing_attribute(lhs);
1813 +
1814 -+ def_stmt = get_def_stmt(var);
1815 ++ def_stmt = get_def_stmt(lhs);
1816 +
1817 + if (!def_stmt)
1818 + return NULL_TREE;
1819 +
1820 + if (gimple_plf(def_stmt, MY_STMT))
1821 -+ return var;
1822 ++ return lhs;
1823 +
1824 + if (pointer_set_contains(visited, def_stmt))
1825 + return expand_visited(def_stmt);
1826 +
1827 + switch (gimple_code(def_stmt)) {
1828 + case GIMPLE_NOP:
1829 -+ check_missing_attribute(var);
1830 ++ check_missing_attribute(lhs);
1831 + return NULL_TREE;
1832 + case GIMPLE_PHI:
1833 -+ return build_new_phi(visited, potentionally_overflowed, var);
1834 ++ return build_new_phi(visited, potentionally_overflowed, lhs);
1835 + case GIMPLE_CALL:
1836 + case GIMPLE_ASM:
1837 -+ return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
1838 ++ return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
1839 + case GIMPLE_ASSIGN:
1840 + switch (gimple_num_ops(def_stmt)) {
1841 + case 2:
1842 -+ return handle_unary_ops(visited, potentionally_overflowed, var);
1843 ++ return handle_unary_ops(visited, potentionally_overflowed, lhs);
1844 + case 3:
1845 -+ return handle_binary_ops(visited, potentionally_overflowed, var);
1846 ++ return handle_binary_ops(visited, potentionally_overflowed, lhs);
1847 +#if BUILDING_GCC_VERSION >= 4007
1848 + case 4:
1849 -+ return handle_ternary_ops(visited, potentionally_overflowed, var);
1850 ++ return handle_ternary_ops(visited, potentionally_overflowed, lhs);
1851 +#endif
1852 + }
1853 + default:
1854 @@ -88569,9 +88601,9 @@ index 0000000..41e11e1
1855 + }
1856 +}
1857 +
1858 -+static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
1859 ++static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
1860 +{
1861 -+ gimple assign;
1862 ++ const_gimple assign;
1863 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
1864 + tree origtype = TREE_TYPE(origarg);
1865 +
1866 @@ -88583,10 +88615,11 @@ index 0000000..41e11e1
1867 + update_stmt(stmt);
1868 +}
1869 +
1870 -+static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
1871 ++static tree get_function_arg(unsigned int argnum, const_gimple stmt, const_tree fndecl)
1872 +{
1873 + const char *origid;
1874 -+ tree arg, origarg;
1875 ++ tree arg;
1876 ++ const_tree origarg;
1877 +
1878 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
1879 + gcc_assert(gimple_call_num_args(stmt) > argnum);
1880 @@ -88610,7 +88643,7 @@ index 0000000..41e11e1
1881 + return NULL_TREE;
1882 +}
1883 +
1884 -+static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
1885 ++static void handle_function_arg(gimple stmt, const_tree fndecl, unsigned int argnum)
1886 +{
1887 + struct pointer_set_t *visited;
1888 + tree arg, newarg;
1889 @@ -88640,7 +88673,7 @@ index 0000000..41e11e1
1890 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, &potentionally_overflowed, BEFORE_STMT);
1891 +}
1892 +
1893 -+static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
1894 ++static void handle_function_by_attribute(gimple stmt, const_tree attr, const_tree fndecl)
1895 +{
1896 + tree p = TREE_VALUE(attr);
1897 + do {
1898 @@ -88649,11 +88682,11 @@ index 0000000..41e11e1
1899 + } while (p);
1900 +}
1901 +
1902 -+static void handle_function_by_hash(gimple stmt, tree fndecl)
1903 ++static void handle_function_by_hash(gimple stmt, const_tree fndecl)
1904 +{
1905 -+ tree orig_fndecl;
1906 ++ const_tree orig_fndecl;
1907 + unsigned int num;
1908 -+ struct size_overflow_hash *hash;
1909 ++ const struct size_overflow_hash *hash;
1910 +
1911 + orig_fndecl = get_original_function_decl(fndecl);
1912 + hash = get_function_hash(orig_fndecl);
1913 @@ -88690,7 +88723,7 @@ index 0000000..41e11e1
1914 + next = bb->next_bb;
1915 +
1916 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
1917 -+ tree fndecl, attr;
1918 ++ const_tree fndecl, attr;
1919 + gimple stmt = gsi_stmt(gsi);
1920 +
1921 + if (!(is_gimple_call(stmt)))
1922
1923 diff --git a/3.5.2/0000_README b/3.5.2/0000_README
1924 index f134d6f..2baff0f 100644
1925 --- a/3.5.2/0000_README
1926 +++ b/3.5.2/0000_README
1927 @@ -2,7 +2,7 @@ README
1928 -----------------------------------------------------------------------------
1929 Individual Patch Descriptions:
1930 -----------------------------------------------------------------------------
1931 -Patch: 4420_grsecurity-2.9.1-3.5.2-201208151951.patch
1932 +Patch: 4420_grsecurity-2.9.1-3.5.2-201208201522.patch
1933 From: http://www.grsecurity.net
1934 Desc: hardened-sources base patch from upstream grsecurity
1935
1936
1937 diff --git a/3.5.2/4420_grsecurity-2.9.1-3.5.2-201208151951.patch b/3.5.2/4420_grsecurity-2.9.1-3.5.2-201208201522.patch
1938 similarity index 99%
1939 rename from 3.5.2/4420_grsecurity-2.9.1-3.5.2-201208151951.patch
1940 rename to 3.5.2/4420_grsecurity-2.9.1-3.5.2-201208201522.patch
1941 index 6ced4b1..61d4d0c 100644
1942 --- a/3.5.2/4420_grsecurity-2.9.1-3.5.2-201208151951.patch
1943 +++ b/3.5.2/4420_grsecurity-2.9.1-3.5.2-201208201522.patch
1944 @@ -81583,7 +81583,7 @@ index 0000000..048d4ff
1945 +}
1946 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
1947 new file mode 100644
1948 -index 0000000..a0fe8b2
1949 +index 0000000..68b646e
1950 --- /dev/null
1951 +++ b/tools/gcc/generate_size_overflow_hash.sh
1952 @@ -0,0 +1,94 @@
1953 @@ -81640,7 +81640,7 @@ index 0000000..a0fe8b2
1954 + params="${data_array[2]}"
1955 + next="${data_array[5]}"
1956 +
1957 -+ echo "struct size_overflow_hash $struct_hash_name = {" >> "$header1"
1958 ++ echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
1959 +
1960 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
1961 + echo -en "\t.param\t= " >> "$header1"
1962 @@ -81655,7 +81655,7 @@ index 0000000..a0fe8b2
1963 +}
1964 +
1965 +create_headers () {
1966 -+ echo "struct size_overflow_hash *size_overflow_hash[$n] = {" >> "$header1"
1967 ++ echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
1968 +}
1969 +
1970 +create_array_elements () {
1971 @@ -85653,10 +85653,10 @@ index 0000000..036c9c6
1972 +_003255_hash acl_alloc_num 1-2 60778 _003255_hash NULL
1973 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
1974 new file mode 100644
1975 -index 0000000..41e11e1
1976 +index 0000000..e9310fa
1977 --- /dev/null
1978 +++ b/tools/gcc/size_overflow_plugin.c
1979 -@@ -0,0 +1,1579 @@
1980 +@@ -0,0 +1,1612 @@
1981 +/*
1982 + * Copyright 2011, 2012 by Emese Revfy <re.emese@×××××.com>
1983 + * Licensed under the GPL v2, or (at your option) v3
1984 @@ -85692,9 +85692,9 @@ index 0000000..41e11e1
1985 +#include "cfgloop.h"
1986 +
1987 +struct size_overflow_hash {
1988 -+ struct size_overflow_hash *next;
1989 -+ const char *name;
1990 -+ unsigned int param;
1991 ++ const struct size_overflow_hash * const next;
1992 ++ const char * const name;
1993 ++ const unsigned int param;
1994 +};
1995 +
1996 +#include "size_overflow_hash.h"
1997 @@ -85717,15 +85717,16 @@ index 0000000..41e11e1
1998 +int plugin_is_GPL_compatible;
1999 +void debug_gimple_stmt(gimple gs);
2000 +
2001 -+static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
2002 ++static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs);
2003 +static tree report_size_overflow_decl;
2004 -+static tree const_char_ptr_type_node;
2005 ++static const_tree const_char_ptr_type_node;
2006 +static unsigned int handle_function(void);
2007 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before);
2008 +static tree get_size_overflow_type(gimple stmt, tree node);
2009 ++static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
2010 +
2011 +static struct plugin_info size_overflow_plugin_info = {
2012 -+ .version = "20120815beta",
2013 ++ .version = "20120820beta",
2014 + .help = "no-size-overflow\tturn off size overflow checking\n",
2015 +};
2016 +
2017 @@ -85778,8 +85779,8 @@ index 0000000..41e11e1
2018 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
2019 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
2020 +
2021 -+ const unsigned int m = 0x57559429;
2022 -+ const unsigned int n = 0x5052acdb;
2023 ++ unsigned int m = 0x57559429;
2024 ++ unsigned int n = 0x5052acdb;
2025 + const unsigned int *key4 = (const unsigned int *)key;
2026 + unsigned int h = len;
2027 + unsigned int k = len + seed + n;
2028 @@ -85810,14 +85811,14 @@ index 0000000..41e11e1
2029 + return fn ^ codes;
2030 +}
2031 +
2032 -+static inline tree get_original_function_decl(tree fndecl)
2033 ++static inline const_tree get_original_function_decl(const_tree fndecl)
2034 +{
2035 + if (DECL_ABSTRACT_ORIGIN(fndecl))
2036 + return DECL_ABSTRACT_ORIGIN(fndecl);
2037 + return fndecl;
2038 +}
2039 +
2040 -+static inline gimple get_def_stmt(tree node)
2041 ++static inline gimple get_def_stmt(const_tree node)
2042 +{
2043 + gcc_assert(node != NULL_TREE);
2044 + gcc_assert(TREE_CODE(node) == SSA_NAME);
2045 @@ -85869,9 +85870,10 @@ index 0000000..41e11e1
2046 + return len;
2047 +}
2048 +
2049 -+static unsigned int get_function_decl(tree fndecl, unsigned char *tree_codes)
2050 ++static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
2051 +{
2052 -+ tree arg, result, type = TREE_TYPE(fndecl);
2053 ++ tree arg;
2054 ++ const_tree result, type = TREE_TYPE(fndecl);
2055 + enum tree_code code = TREE_CODE(type);
2056 + size_t len = 0;
2057 +
2058 @@ -85900,10 +85902,10 @@ index 0000000..41e11e1
2059 + return len;
2060 +}
2061 +
2062 -+static struct size_overflow_hash *get_function_hash(tree fndecl)
2063 ++static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
2064 +{
2065 + unsigned int hash;
2066 -+ struct size_overflow_hash *entry;
2067 ++ const struct size_overflow_hash *entry;
2068 + unsigned char tree_codes[CODES_LIMIT];
2069 + size_t len;
2070 + const char *func_name = NAME(fndecl);
2071 @@ -85924,9 +85926,9 @@ index 0000000..41e11e1
2072 + return NULL;
2073 +}
2074 +
2075 -+static void check_arg_type(tree var)
2076 ++static void check_arg_type(const_tree arg)
2077 +{
2078 -+ tree type = TREE_TYPE(var);
2079 ++ const_tree type = TREE_TYPE(arg);
2080 + enum tree_code code = TREE_CODE(type);
2081 +
2082 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
2083 @@ -85934,7 +85936,7 @@ index 0000000..41e11e1
2084 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
2085 +}
2086 +
2087 -+static int find_arg_number(tree arg, tree func)
2088 ++static int find_arg_number(const_tree arg, const_tree func)
2089 +{
2090 + tree var;
2091 + bool match = false;
2092 @@ -85960,7 +85962,7 @@ index 0000000..41e11e1
2093 + return argnum;
2094 +}
2095 +
2096 -+static void print_missing_msg(tree func, unsigned int argnum)
2097 ++static void print_missing_msg(const_tree func, unsigned int argnum)
2098 +{
2099 + unsigned int new_hash;
2100 + size_t len;
2101 @@ -85973,16 +85975,15 @@ index 0000000..41e11e1
2102 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
2103 +}
2104 +
2105 -+static void check_missing_attribute(tree arg)
2106 ++static void check_missing_attribute(const_tree arg)
2107 +{
2108 -+ tree type, func = get_original_function_decl(current_function_decl);
2109 ++ const_tree type = TREE_TYPE(arg);
2110 ++ const_tree func = get_original_function_decl(current_function_decl);
2111 + unsigned int argnum;
2112 -+ struct size_overflow_hash *hash;
2113 ++ const struct size_overflow_hash *hash;
2114 +
2115 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
2116 +
2117 -+ type = TREE_TYPE(arg);
2118 -+
2119 + if (TREE_CODE(type) == POINTER_TYPE)
2120 + return;
2121 +
2122 @@ -86023,9 +86024,9 @@ index 0000000..41e11e1
2123 + return assign;
2124 +}
2125 +
2126 -+static bool is_bool(tree node)
2127 ++static bool is_bool(const_tree node)
2128 +{
2129 -+ tree type;
2130 ++ const_tree type;
2131 +
2132 + if (node == NULL_TREE)
2133 + return false;
2134 @@ -86049,26 +86050,25 @@ index 0000000..41e11e1
2135 + return fold_convert(type, var);
2136 +}
2137 +
2138 -+static gimple build_cast_stmt(tree type, tree var, tree new_var, gimple_stmt_iterator *gsi, bool before)
2139 ++static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
2140 +{
2141 + gimple assign;
2142 -+ location_t loc;
2143 +
2144 -+ gcc_assert(type != NULL_TREE && var != NULL_TREE);
2145 ++ gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
2146 + if (gsi_end_p(*gsi) && before == BEFORE_STMT)
2147 + gcc_unreachable();
2148 +
2149 -+ if (new_var == CREATE_NEW_VAR)
2150 -+ new_var = create_new_var(type);
2151 ++ if (lhs == CREATE_NEW_VAR)
2152 ++ lhs = create_new_var(dst_type);
2153 +
2154 -+ assign = gimple_build_assign(new_var, cast_a_tree(type, var));
2155 ++ assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
2156 +
2157 + if (!gsi_end_p(*gsi)) {
2158 -+ loc = gimple_location(gsi_stmt(*gsi));
2159 ++ location_t loc = gimple_location(gsi_stmt(*gsi));
2160 + gimple_set_location(assign, loc);
2161 + }
2162 +
2163 -+ gimple_set_lhs(assign, make_ssa_name(new_var, assign));
2164 ++ gimple_set_lhs(assign, make_ssa_name(lhs, assign));
2165 +
2166 + if (before)
2167 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
2168 @@ -86082,7 +86082,7 @@ index 0000000..41e11e1
2169 +
2170 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
2171 +{
2172 -+ gimple assign;
2173 ++ const_gimple assign;
2174 + gimple_stmt_iterator gsi;
2175 +
2176 + if (new_rhs1 == NULL_TREE)
2177 @@ -86096,9 +86096,25 @@ index 0000000..41e11e1
2178 + return new_rhs1;
2179 +}
2180 +
2181 ++static tree follow_overflow_type_and_dup(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree node, tree new_rhs1, tree new_rhs2, tree new_rhs3)
2182 ++{
2183 ++ tree size_overflow_type = get_size_overflow_type(stmt, node);
2184 ++
2185 ++ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
2186 ++
2187 ++ if (new_rhs2 != NULL_TREE)
2188 ++ new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
2189 ++
2190 ++ if (new_rhs3 != NULL_TREE)
2191 ++ new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
2192 ++
2193 ++ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
2194 ++}
2195 ++
2196 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
2197 +{
2198 -+ tree oldstmt_rhs1, size_overflow_type, lhs;
2199 ++ const_tree oldstmt_rhs1;
2200 ++ tree size_overflow_type, lhs;
2201 + enum tree_code code;
2202 + gimple stmt;
2203 + gimple_stmt_iterator gsi;
2204 @@ -86126,7 +86142,7 @@ index 0000000..41e11e1
2205 + pointer_set_insert(visited, oldstmt);
2206 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
2207 + basic_block next_bb, cur_bb;
2208 -+ edge e;
2209 ++ const_edge e;
2210 +
2211 + gcc_assert(before == false);
2212 + gcc_assert(stmt_can_throw_internal(oldstmt));
2213 @@ -86156,9 +86172,9 @@ index 0000000..41e11e1
2214 +
2215 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
2216 +{
2217 -+ tree new_var, lhs = gimple_get_lhs(oldstmt);
2218 + gimple stmt;
2219 + gimple_stmt_iterator gsi;
2220 ++ tree new_var, lhs = gimple_get_lhs(oldstmt);
2221 +
2222 + if (!*potentionally_overflowed)
2223 + return NULL_TREE;
2224 @@ -86211,7 +86227,7 @@ index 0000000..41e11e1
2225 + return gimple_get_lhs(stmt);
2226 +}
2227 +
2228 -+static gimple overflow_create_phi_node(gimple oldstmt, tree var)
2229 ++static gimple overflow_create_phi_node(gimple oldstmt, tree result)
2230 +{
2231 + basic_block bb;
2232 + gimple phi;
2233 @@ -86219,7 +86235,7 @@ index 0000000..41e11e1
2234 +
2235 + bb = gsi_bb(gsi);
2236 +
2237 -+ phi = create_phi_node(var, bb);
2238 ++ phi = create_phi_node(result, bb);
2239 + gsi = gsi_last(phi_nodes(bb));
2240 + gsi_remove(&gsi, false);
2241 +
2242 @@ -86243,7 +86259,7 @@ index 0000000..41e11e1
2243 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
2244 +{
2245 + basic_block bb;
2246 -+ gimple newstmt;
2247 ++ const_gimple newstmt;
2248 + gimple_stmt_iterator gsi;
2249 + bool before = BEFORE_STMT;
2250 +
2251 @@ -86265,7 +86281,7 @@ index 0000000..41e11e1
2252 + return gimple_get_lhs(newstmt);
2253 +}
2254 +
2255 -+static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
2256 ++static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
2257 +{
2258 + gimple newstmt;
2259 + gimple_stmt_iterator gsi;
2260 @@ -86302,7 +86318,7 @@ index 0000000..41e11e1
2261 +
2262 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree size_overflow_type, tree arg, tree new_var)
2263 +{
2264 -+ gimple newstmt;
2265 ++ const_gimple newstmt;
2266 + tree new_rhs;
2267 +
2268 + new_rhs = expand(visited, potentionally_overflowed, arg);
2269 @@ -86315,27 +86331,28 @@ index 0000000..41e11e1
2270 + return gimple_get_lhs(newstmt);
2271 +}
2272 +
2273 -+static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
2274 ++static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, tree orig_result)
2275 +{
2276 -+ gimple phi, oldstmt = get_def_stmt(var);
2277 -+ tree new_var, size_overflow_type;
2278 -+ unsigned int i, n = gimple_phi_num_args(oldstmt);
2279 ++ gimple phi, oldstmt = get_def_stmt(orig_result);
2280 ++ tree new_result, size_overflow_type;
2281 ++ unsigned int i;
2282 ++ unsigned int n = gimple_phi_num_args(oldstmt);
2283 +
2284 -+ size_overflow_type = get_size_overflow_type(oldstmt, var);
2285 ++ size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
2286 +
2287 -+ new_var = create_new_var(size_overflow_type);
2288 ++ new_result = create_new_var(size_overflow_type);
2289 +
2290 + pointer_set_insert(visited, oldstmt);
2291 -+ phi = overflow_create_phi_node(oldstmt, new_var);
2292 ++ phi = overflow_create_phi_node(oldstmt, new_result);
2293 + for (i = 0; i < n; i++) {
2294 + tree arg, lhs;
2295 +
2296 + arg = gimple_phi_arg_def(oldstmt, i);
2297 + if (is_gimple_constant(arg))
2298 + arg = cast_a_tree(size_overflow_type, arg);
2299 -+ lhs = build_new_phi_arg(visited, potentionally_overflowed, size_overflow_type, arg, new_var);
2300 ++ lhs = build_new_phi_arg(visited, potentionally_overflowed, size_overflow_type, arg, new_result);
2301 + if (lhs == NULL_TREE)
2302 -+ lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_var, i);
2303 ++ lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
2304 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
2305 + }
2306 +
2307 @@ -86343,9 +86360,9 @@ index 0000000..41e11e1
2308 + return gimple_phi_result(phi);
2309 +}
2310 +
2311 -+static tree change_assign_rhs(gimple stmt, tree orig_rhs, tree new_rhs)
2312 ++static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
2313 +{
2314 -+ gimple assign;
2315 ++ const_gimple assign;
2316 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
2317 + tree origtype = TREE_TYPE(orig_rhs);
2318 +
2319 @@ -86358,18 +86375,18 @@ index 0000000..41e11e1
2320 +static void change_rhs1(gimple stmt, tree new_rhs1)
2321 +{
2322 + tree assign_rhs;
2323 -+ tree rhs = gimple_assign_rhs1(stmt);
2324 ++ const_tree rhs = gimple_assign_rhs1(stmt);
2325 +
2326 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
2327 + gimple_assign_set_rhs1(stmt, assign_rhs);
2328 + update_stmt(stmt);
2329 +}
2330 +
2331 -+static bool check_mode_type(gimple stmt)
2332 ++static bool check_mode_type(const_gimple stmt)
2333 +{
2334 -+ tree lhs = gimple_get_lhs(stmt);
2335 -+ tree lhs_type = TREE_TYPE(lhs);
2336 -+ tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
2337 ++ const_tree lhs = gimple_get_lhs(stmt);
2338 ++ const_tree lhs_type = TREE_TYPE(lhs);
2339 ++ const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
2340 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
2341 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
2342 +
2343 @@ -86382,13 +86399,13 @@ index 0000000..41e11e1
2344 + return true;
2345 +}
2346 +
2347 -+static bool check_undefined_integer_operation(gimple stmt)
2348 ++static bool check_undefined_integer_operation(const_gimple stmt)
2349 +{
2350 -+ gimple def_stmt;
2351 -+ tree lhs = gimple_get_lhs(stmt);
2352 -+ tree rhs1 = gimple_assign_rhs1(stmt);
2353 -+ tree rhs1_type = TREE_TYPE(rhs1);
2354 -+ tree lhs_type = TREE_TYPE(lhs);
2355 ++ const_gimple def_stmt;
2356 ++ const_tree lhs = gimple_get_lhs(stmt);
2357 ++ const_tree rhs1 = gimple_assign_rhs1(stmt);
2358 ++ const_tree rhs1_type = TREE_TYPE(rhs1);
2359 ++ const_tree lhs_type = TREE_TYPE(lhs);
2360 +
2361 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
2362 + return false;
2363 @@ -86402,9 +86419,9 @@ index 0000000..41e11e1
2364 + return true;
2365 +}
2366 +
2367 -+static bool is_a_cast_and_const_overflow(tree no_const_rhs)
2368 ++static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
2369 +{
2370 -+ tree rhs1, lhs, rhs1_type, lhs_type;
2371 ++ const_tree rhs1, lhs, rhs1_type, lhs_type;
2372 + enum machine_mode lhs_mode, rhs_mode;
2373 + gimple def_stmt = get_def_stmt(no_const_rhs);
2374 +
2375 @@ -86427,8 +86444,8 @@ index 0000000..41e11e1
2376 +{
2377 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
2378 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
2379 -+ tree rhs1_type = TREE_TYPE(rhs1);
2380 -+ tree lhs_type = TREE_TYPE(lhs);
2381 ++ const_tree rhs1_type = TREE_TYPE(rhs1);
2382 ++ const_tree lhs_type = TREE_TYPE(lhs);
2383 +
2384 + *potentionally_overflowed = true;
2385 +
2386 @@ -86440,23 +86457,18 @@ index 0000000..41e11e1
2387 + if (gimple_plf(stmt, MY_STMT))
2388 + return lhs;
2389 +
2390 -+ if (gimple_plf(stmt, NO_CAST_CHECK)) {
2391 -+ size_overflow_type = get_size_overflow_type(stmt, rhs1);
2392 -+ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
2393 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
2394 -+ }
2395 ++ if (gimple_plf(stmt, NO_CAST_CHECK))
2396 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
2397 +
2398 -+ if (!gimple_assign_cast_p(stmt)) {
2399 -+ size_overflow_type = get_size_overflow_type(stmt, lhs);
2400 ++ if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
2401 ++ size_overflow_type = get_size_overflow_type(stmt, rhs1);
2402 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
2403 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
2404 ++ check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, potentionally_overflowed, BEFORE_STMT);
2405 ++ return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
2406 + }
2407 +
2408 -+ if (check_undefined_integer_operation(stmt)) {
2409 -+ size_overflow_type = get_size_overflow_type(stmt, lhs);
2410 -+ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
2411 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
2412 -+ }
2413 ++ if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
2414 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
2415 +
2416 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
2417 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
2418 @@ -86525,7 +86537,7 @@ index 0000000..41e11e1
2419 +static tree create_string_param(tree string)
2420 +{
2421 + tree i_type, a_type;
2422 -+ int length = TREE_STRING_LENGTH(string);
2423 ++ const int length = TREE_STRING_LENGTH(string);
2424 +
2425 + gcc_assert(length > 0);
2426 +
2427 @@ -86539,12 +86551,14 @@ index 0000000..41e11e1
2428 + return build1(ADDR_EXPR, ptr_type_node, string);
2429 +}
2430 +
2431 -+static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg, bool min)
2432 ++static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
2433 +{
2434 -+ gimple func_stmt, def_stmt;
2435 -+ tree current_func, loc_file, loc_line, ssa_name;
2436 ++ gimple func_stmt;
2437 ++ const_gimple def_stmt;
2438 ++ const_tree loc_line;
2439 ++ tree loc_file, ssa_name, current_func;
2440 + expanded_location xloc;
2441 -+ char ssa_name_buf[100];
2442 ++ char ssa_name_buf[256];
2443 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
2444 +
2445 + def_stmt = get_def_stmt(arg);
2446 @@ -86564,8 +86578,8 @@ index 0000000..41e11e1
2447 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
2448 + current_func = create_string_param(current_func);
2449 +
2450 -+ snprintf(ssa_name_buf, sizeof(ssa_name_buf), "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
2451 -+ ssa_name = build_string(sizeof(ssa_name_buf), ssa_name_buf);
2452 ++ snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
2453 ++ ssa_name = build_string(256, ssa_name_buf);
2454 + ssa_name = create_string_param(ssa_name);
2455 +
2456 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
2457 @@ -86574,7 +86588,7 @@ index 0000000..41e11e1
2458 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
2459 +}
2460 +
2461 -+static void __unused print_the_code_insertions(gimple stmt)
2462 ++static void __unused print_the_code_insertions(const_gimple stmt)
2463 +{
2464 + location_t loc = gimple_location(stmt);
2465 +
2466 @@ -86622,7 +86636,9 @@ index 0000000..41e11e1
2467 +
2468 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before)
2469 +{
2470 -+ tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min, rhs_type = TREE_TYPE(rhs);
2471 ++ const_tree rhs_type = TREE_TYPE(rhs);
2472 ++ tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
2473 ++
2474 + gcc_assert(rhs_type != NULL_TREE);
2475 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
2476 +
2477 @@ -86644,27 +86660,27 @@ index 0000000..41e11e1
2478 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
2479 +}
2480 +
2481 -+static tree get_handle_const_assign_size_overflow_type(gimple def_stmt, tree var_rhs)
2482 ++static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
2483 +{
2484 -+ gimple var_rhs_def_stmt;
2485 ++ gimple change_rhs_def_stmt;
2486 + tree lhs = gimple_get_lhs(def_stmt);
2487 + tree lhs_type = TREE_TYPE(lhs);
2488 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
2489 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
2490 +
2491 -+ if (var_rhs == NULL_TREE)
2492 ++ if (change_rhs == NULL_TREE)
2493 + return get_size_overflow_type(def_stmt, lhs);
2494 +
2495 -+ var_rhs_def_stmt = get_def_stmt(var_rhs);
2496 ++ change_rhs_def_stmt = get_def_stmt(change_rhs);
2497 +
2498 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
2499 -+ return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
2500 ++ return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
2501 +
2502 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
2503 -+ return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
2504 ++ return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
2505 +
2506 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
2507 -+ return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
2508 ++ return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
2509 +
2510 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
2511 + debug_gimple_stmt(def_stmt);
2512 @@ -86674,45 +86690,16 @@ index 0000000..41e11e1
2513 + return get_size_overflow_type(def_stmt, lhs);
2514 +}
2515 +
2516 -+static tree handle_const_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple def_stmt, tree var_rhs, tree new_rhs1, tree new_rhs2)
2517 ++static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
2518 +{
2519 -+ tree new_rhs, size_overflow_type, orig_rhs;
2520 -+ void (*gimple_assign_set_rhs)(gimple, tree);
2521 -+ tree rhs1 = gimple_assign_rhs1(def_stmt);
2522 -+ tree rhs2 = gimple_assign_rhs2(def_stmt);
2523 -+ tree lhs = gimple_get_lhs(def_stmt);
2524 -+
2525 -+ if (var_rhs == NULL_TREE)
2526 -+ return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
2527 -+
2528 -+ if (new_rhs2 == NULL_TREE) {
2529 -+ size_overflow_type = get_handle_const_assign_size_overflow_type(def_stmt, new_rhs1);
2530 -+ new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
2531 -+ orig_rhs = rhs1;
2532 -+ gimple_assign_set_rhs = &gimple_assign_set_rhs1;
2533 -+ } else {
2534 -+ size_overflow_type = get_handle_const_assign_size_overflow_type(def_stmt, new_rhs2);
2535 -+ new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
2536 -+ orig_rhs = rhs2;
2537 -+ gimple_assign_set_rhs = &gimple_assign_set_rhs2;
2538 -+ }
2539 -+
2540 -+ var_rhs = cast_to_new_size_overflow_type(def_stmt, var_rhs, size_overflow_type, BEFORE_STMT);
2541 -+
2542 -+ if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
2543 -+ return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
2544 -+
2545 -+ if (!is_a_cast_and_const_overflow(orig_rhs))
2546 -+ check_size_overflow(def_stmt, size_overflow_type, var_rhs, orig_rhs, potentionally_overflowed, BEFORE_STMT);
2547 -+
2548 -+ new_rhs = change_assign_rhs(def_stmt, orig_rhs, var_rhs);
2549 -+ gimple_assign_set_rhs(def_stmt, new_rhs);
2550 -+ update_stmt(def_stmt);
2551 -+
2552 -+ return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
2553 ++ if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
2554 ++ return false;
2555 ++ if (!is_gimple_constant(rhs))
2556 ++ return false;
2557 ++ return true;
2558 +}
2559 +
2560 -+static tree get_cast_def_stmt_rhs(tree new_rhs)
2561 ++static tree get_cast_def_stmt_rhs(const_tree new_rhs)
2562 +{
2563 + gimple def_stmt;
2564 +
2565 @@ -86726,7 +86713,8 @@ index 0000000..41e11e1
2566 +static tree cast_to_int_TI_type_and_check(bool *potentionally_overflowed, gimple stmt, tree new_rhs)
2567 +{
2568 + gimple_stmt_iterator gsi;
2569 -+ gimple cast_stmt, def_stmt;
2570 ++ const_gimple cast_stmt;
2571 ++ gimple def_stmt;
2572 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
2573 +
2574 + if (mode != TImode && mode != DImode) {
2575 @@ -86753,13 +86741,13 @@ index 0000000..41e11e1
2576 + return new_rhs;
2577 +}
2578 +
2579 -+static bool is_an_integer_trunction(gimple stmt)
2580 ++static bool is_an_integer_trunction(const_gimple stmt)
2581 +{
2582 + gimple rhs1_def_stmt, rhs2_def_stmt;
2583 -+ tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
2584 ++ const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
2585 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
2586 -+ tree rhs1 = gimple_assign_rhs1(stmt);
2587 -+ tree rhs2 = gimple_assign_rhs2(stmt);
2588 ++ const_tree rhs1 = gimple_assign_rhs1(stmt);
2589 ++ const_tree rhs2 = gimple_assign_rhs2(stmt);
2590 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
2591 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
2592 +
2593 @@ -86790,7 +86778,7 @@ index 0000000..41e11e1
2594 +
2595 +static tree handle_integer_truncation(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
2596 +{
2597 -+ tree new_rhs1, new_rhs2, size_overflow_type;
2598 ++ tree new_rhs1, new_rhs2;
2599 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
2600 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
2601 + gimple assign, stmt = get_def_stmt(lhs);
2602 @@ -86818,15 +86806,64 @@ index 0000000..41e11e1
2603 + new_lhs = gimple_get_lhs(assign);
2604 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, potentionally_overflowed, AFTER_STMT);
2605 +
2606 -+ size_overflow_type = get_size_overflow_type(stmt, lhs);
2607 -+ new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
2608 -+ new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
2609 -+ return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
2610 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
2611 ++}
2612 ++
2613 ++static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
2614 ++{
2615 ++ const_gimple def_stmt;
2616 ++
2617 ++ if (TREE_CODE(rhs) != SSA_NAME)
2618 ++ return false;
2619 ++
2620 ++ if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
2621 ++ return false;
2622 ++
2623 ++ def_stmt = get_def_stmt(rhs);
2624 ++ if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
2625 ++ return false;
2626 ++
2627 ++ return true;
2628 ++}
2629 ++
2630 ++static tree handle_intentional_overflow(struct pointer_set_t *visited, bool *potentionally_overflowed, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
2631 ++{
2632 ++ tree new_rhs, size_overflow_type, orig_rhs;
2633 ++ void (*gimple_assign_set_rhs)(gimple, tree);
2634 ++ tree rhs1 = gimple_assign_rhs1(stmt);
2635 ++ tree rhs2 = gimple_assign_rhs2(stmt);
2636 ++ tree lhs = gimple_get_lhs(stmt);
2637 ++
2638 ++ if (change_rhs == NULL_TREE)
2639 ++ return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
2640 ++
2641 ++ if (new_rhs2 == NULL_TREE) {
2642 ++ size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
2643 ++ new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
2644 ++ orig_rhs = rhs1;
2645 ++ gimple_assign_set_rhs = &gimple_assign_set_rhs1;
2646 ++ } else {
2647 ++ size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
2648 ++ new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
2649 ++ orig_rhs = rhs2;
2650 ++ gimple_assign_set_rhs = &gimple_assign_set_rhs2;
2651 ++ }
2652 ++
2653 ++ change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
2654 ++
2655 ++ if (check_overflow)
2656 ++ check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, potentionally_overflowed, BEFORE_STMT);
2657 ++
2658 ++ new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
2659 ++ gimple_assign_set_rhs(stmt, new_rhs);
2660 ++ update_stmt(stmt);
2661 ++
2662 ++ return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
2663 +}
2664 +
2665 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
2666 +{
2667 -+ tree rhs1, rhs2, size_overflow_type, new_lhs;
2668 ++ tree rhs1, rhs2, new_lhs;
2669 + gimple def_stmt = get_def_stmt(lhs);
2670 + tree new_rhs1 = NULL_TREE;
2671 + tree new_rhs2 = NULL_TREE;
2672 @@ -86864,18 +86901,17 @@ index 0000000..41e11e1
2673 + if (TREE_CODE(rhs2) == SSA_NAME)
2674 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
2675 +
2676 -+ if (is_gimple_constant(rhs2))
2677 -+ return handle_const_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
2678 -+
2679 -+ if (is_gimple_constant(rhs1))
2680 -+ return handle_const_assign(visited, potentionally_overflowed, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
2681 -+
2682 -+ size_overflow_type = get_size_overflow_type(def_stmt, lhs);
2683 ++ if (is_a_neg_overflow(def_stmt, rhs2))
2684 ++ return handle_intentional_overflow(visited, potentionally_overflowed, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
2685 ++ if (is_a_neg_overflow(def_stmt, rhs1))
2686 ++ return handle_intentional_overflow(visited, potentionally_overflowed, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
2687 +
2688 -+ new_rhs1 = cast_to_new_size_overflow_type(def_stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
2689 -+ new_rhs2 = cast_to_new_size_overflow_type(def_stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
2690 ++ if (is_a_constant_overflow(def_stmt, rhs2))
2691 ++ return handle_intentional_overflow(visited, potentionally_overflowed, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
2692 ++ if (is_a_constant_overflow(def_stmt, rhs1))
2693 ++ return handle_intentional_overflow(visited, potentionally_overflowed, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
2694 +
2695 -+ return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
2696 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
2697 +}
2698 +
2699 +#if BUILDING_GCC_VERSION >= 4007
2700 @@ -86888,14 +86924,14 @@ index 0000000..41e11e1
2701 + return expand(visited, potentionally_overflowed, rhs);
2702 +}
2703 +
2704 -+static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
2705 ++static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
2706 +{
2707 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
2708 -+ gimple def_stmt = get_def_stmt(var);
2709 ++ gimple def_stmt = get_def_stmt(lhs);
2710 +
2711 + *potentionally_overflowed = true;
2712 +
2713 -+ size_overflow_type = get_size_overflow_type(def_stmt, var);
2714 ++ size_overflow_type = get_size_overflow_type(def_stmt, lhs);
2715 +
2716 + rhs1 = gimple_assign_rhs1(def_stmt);
2717 + rhs2 = gimple_assign_rhs2(def_stmt);
2718 @@ -86904,11 +86940,7 @@ index 0000000..41e11e1
2719 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs2);
2720 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs3);
2721 +
2722 -+ new_rhs1 = cast_to_new_size_overflow_type(def_stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
2723 -+ new_rhs2 = cast_to_new_size_overflow_type(def_stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
2724 -+ new_rhs3 = cast_to_new_size_overflow_type(def_stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
2725 -+
2726 -+ return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
2727 ++ return follow_overflow_type_and_dup(visited, potentionally_overflowed, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
2728 +}
2729 +#endif
2730 +
2731 @@ -86943,7 +86975,7 @@ index 0000000..41e11e1
2732 +
2733 +static tree expand_visited(gimple def_stmt)
2734 +{
2735 -+ gimple next_stmt;
2736 ++ const_gimple next_stmt;
2737 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
2738 +
2739 + gsi_next(&gsi);
2740 @@ -86961,51 +86993,51 @@ index 0000000..41e11e1
2741 + }
2742 +}
2743 +
2744 -+static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
2745 ++static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
2746 +{
2747 + gimple def_stmt;
2748 -+ enum tree_code code = TREE_CODE(TREE_TYPE(var));
2749 ++ enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
2750 +
2751 -+ if (is_gimple_constant(var))
2752 ++ if (is_gimple_constant(lhs))
2753 + return NULL_TREE;
2754 +
2755 -+ if (TREE_CODE(var) == ADDR_EXPR)
2756 ++ if (TREE_CODE(lhs) == ADDR_EXPR)
2757 + return NULL_TREE;
2758 +
2759 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
2760 +
2761 -+ if (TREE_CODE(SSA_NAME_VAR(var)) == PARM_DECL)
2762 -+ check_missing_attribute(var);
2763 ++ if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
2764 ++ check_missing_attribute(lhs);
2765 +
2766 -+ def_stmt = get_def_stmt(var);
2767 ++ def_stmt = get_def_stmt(lhs);
2768 +
2769 + if (!def_stmt)
2770 + return NULL_TREE;
2771 +
2772 + if (gimple_plf(def_stmt, MY_STMT))
2773 -+ return var;
2774 ++ return lhs;
2775 +
2776 + if (pointer_set_contains(visited, def_stmt))
2777 + return expand_visited(def_stmt);
2778 +
2779 + switch (gimple_code(def_stmt)) {
2780 + case GIMPLE_NOP:
2781 -+ check_missing_attribute(var);
2782 ++ check_missing_attribute(lhs);
2783 + return NULL_TREE;
2784 + case GIMPLE_PHI:
2785 -+ return build_new_phi(visited, potentionally_overflowed, var);
2786 ++ return build_new_phi(visited, potentionally_overflowed, lhs);
2787 + case GIMPLE_CALL:
2788 + case GIMPLE_ASM:
2789 -+ return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
2790 ++ return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
2791 + case GIMPLE_ASSIGN:
2792 + switch (gimple_num_ops(def_stmt)) {
2793 + case 2:
2794 -+ return handle_unary_ops(visited, potentionally_overflowed, var);
2795 ++ return handle_unary_ops(visited, potentionally_overflowed, lhs);
2796 + case 3:
2797 -+ return handle_binary_ops(visited, potentionally_overflowed, var);
2798 ++ return handle_binary_ops(visited, potentionally_overflowed, lhs);
2799 +#if BUILDING_GCC_VERSION >= 4007
2800 + case 4:
2801 -+ return handle_ternary_ops(visited, potentionally_overflowed, var);
2802 ++ return handle_ternary_ops(visited, potentionally_overflowed, lhs);
2803 +#endif
2804 + }
2805 + default:
2806 @@ -87015,9 +87047,9 @@ index 0000000..41e11e1
2807 + }
2808 +}
2809 +
2810 -+static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
2811 ++static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
2812 +{
2813 -+ gimple assign;
2814 ++ const_gimple assign;
2815 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
2816 + tree origtype = TREE_TYPE(origarg);
2817 +
2818 @@ -87029,10 +87061,11 @@ index 0000000..41e11e1
2819 + update_stmt(stmt);
2820 +}
2821 +
2822 -+static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
2823 ++static tree get_function_arg(unsigned int argnum, const_gimple stmt, const_tree fndecl)
2824 +{
2825 + const char *origid;
2826 -+ tree arg, origarg;
2827 ++ tree arg;
2828 ++ const_tree origarg;
2829 +
2830 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
2831 + gcc_assert(gimple_call_num_args(stmt) > argnum);
2832 @@ -87056,7 +87089,7 @@ index 0000000..41e11e1
2833 + return NULL_TREE;
2834 +}
2835 +
2836 -+static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
2837 ++static void handle_function_arg(gimple stmt, const_tree fndecl, unsigned int argnum)
2838 +{
2839 + struct pointer_set_t *visited;
2840 + tree arg, newarg;
2841 @@ -87086,7 +87119,7 @@ index 0000000..41e11e1
2842 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, &potentionally_overflowed, BEFORE_STMT);
2843 +}
2844 +
2845 -+static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
2846 ++static void handle_function_by_attribute(gimple stmt, const_tree attr, const_tree fndecl)
2847 +{
2848 + tree p = TREE_VALUE(attr);
2849 + do {
2850 @@ -87095,11 +87128,11 @@ index 0000000..41e11e1
2851 + } while (p);
2852 +}
2853 +
2854 -+static void handle_function_by_hash(gimple stmt, tree fndecl)
2855 ++static void handle_function_by_hash(gimple stmt, const_tree fndecl)
2856 +{
2857 -+ tree orig_fndecl;
2858 ++ const_tree orig_fndecl;
2859 + unsigned int num;
2860 -+ struct size_overflow_hash *hash;
2861 ++ const struct size_overflow_hash *hash;
2862 +
2863 + orig_fndecl = get_original_function_decl(fndecl);
2864 + hash = get_function_hash(orig_fndecl);
2865 @@ -87136,7 +87169,7 @@ index 0000000..41e11e1
2866 + next = bb->next_bb;
2867 +
2868 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
2869 -+ tree fndecl, attr;
2870 ++ const_tree fndecl, attr;
2871 + gimple stmt = gsi_stmt(gsi);
2872 +
2873 + if (!(is_gimple_call(stmt)))