diff options
author | Richard Biener <rguenther@suse.de> | 2015-09-23 14:09:48 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2015-09-23 14:09:48 +0000 |
commit | ef537cc859dd149230454398078da6d3128cfd9a (patch) | |
tree | 67581402c59ae589386b720bd313c301e37ab859 /gcc/fold-const.c | |
parent | 9e07d08d785f0c612c0dd1c0ed713ebaf8298720 (diff) | |
download | gcc-ef537cc859dd149230454398078da6d3128cfd9a.zip gcc-ef537cc859dd149230454398078da6d3128cfd9a.tar.gz gcc-ef537cc859dd149230454398078da6d3128cfd9a.tar.bz2 |
re PR middle-end/67662 (-fsanitize=undefined cries wolf for X - 1 + X when X is 2**30)
2015-09-23 Richard Biener <rguenther@suse.de>
PR middle-end/67662
* fold-const.c (fold_binary_loc): Do not reassociate two vars with
undefined overflow unless they will cancel out.
* gcc.dg/ubsan/pr67662.c: New testcase.
From-SVN: r228051
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c140c62..7231fd6 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9493,25 +9493,32 @@ fold_binary_loc (location_t loc, { tree tmp0 = var0; tree tmp1 = var1; + bool one_neg = false; if (TREE_CODE (tmp0) == NEGATE_EXPR) - tmp0 = TREE_OPERAND (tmp0, 0); + { + tmp0 = TREE_OPERAND (tmp0, 0); + one_neg = !one_neg; + } if (CONVERT_EXPR_P (tmp0) && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (tmp0, 0))) && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (tmp0, 0))) <= TYPE_PRECISION (atype))) tmp0 = TREE_OPERAND (tmp0, 0); if (TREE_CODE (tmp1) == NEGATE_EXPR) - tmp1 = TREE_OPERAND (tmp1, 0); + { + tmp1 = TREE_OPERAND (tmp1, 0); + one_neg = !one_neg; + } if (CONVERT_EXPR_P (tmp1) && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (tmp1, 0))) && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (tmp1, 0))) <= TYPE_PRECISION (atype))) tmp1 = TREE_OPERAND (tmp1, 0); /* The only case we can still associate with two variables - is if they are the same, modulo negation and bit-pattern - preserving conversions. */ - if (!operand_equal_p (tmp0, tmp1, 0)) + is if they cancel out. */ + if (!one_neg + || !operand_equal_p (tmp0, tmp1, 0)) ok = false; } } |