]>
Commit | Line | Data |
---|---|---|
74f9f6b5 PS |
1 | PR tree-optimization/27364 |
2 | * tree-vrp.c (vrp_int_const_binop): Fix detection of overflow from | |
3 | multiply expressions. | |
4 | ||
5 | --- gcc-4_1-branch/gcc/tree-vrp.c.orig 2006-02-10 09:46:43.000000000 +0100 | |
6 | +++ gcc-4_1-branch/gcc/tree-vrp.c 2006-05-02 22:59:17.000000000 +0200 | |
7 | @@ -1101,17 +1101,39 @@ | |
8 | if (TYPE_UNSIGNED (TREE_TYPE (val1))) | |
9 | { | |
10 | int checkz = compare_values (res, val1); | |
11 | + bool overflow = false; | |
12 | ||
13 | /* Ensure that res = val1 [+*] val2 >= val1 | |
14 | or that res = val1 - val2 <= val1. */ | |
15 | - if (((code == PLUS_EXPR || code == MULT_EXPR) | |
16 | + if ((code == PLUS_EXPR | |
17 | && !(checkz == 1 || checkz == 0)) | |
18 | || (code == MINUS_EXPR | |
19 | && !(checkz == 0 || checkz == -1))) | |
20 | { | |
21 | + overflow = true; | |
22 | + } | |
23 | + /* Checking for multiplication overflow is done by dividing the | |
24 | + output of the multiplication by the first input of the | |
25 | + multiplication. If the result of that division operation is | |
26 | + not equal to the second input of the multiplication, then the | |
27 | + multiplication overflowed. */ | |
28 | + else if (code == MULT_EXPR && !integer_zerop (val1)) | |
29 | + { | |
30 | + tree tmp = int_const_binop (TRUNC_DIV_EXPR, | |
31 | + TYPE_MAX_VALUE (TREE_TYPE (val1)), | |
32 | + val1, 0); | |
33 | + int check = compare_values (tmp, val2); | |
34 | + | |
35 | + if (check != 0) | |
36 | + overflow = true; | |
37 | + } | |
38 | + | |
39 | + if (overflow) | |
40 | + { | |
41 | res = copy_node (res); | |
42 | TREE_OVERFLOW (res) = 1; | |
43 | } | |
44 | + | |
45 | } | |
46 | else if (TREE_OVERFLOW (res) | |
47 | && !TREE_OVERFLOW (val1) |