diff options
author | Marek Polacek <polacek@redhat.com> | 2014-11-12 14:36:41 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-11-12 14:36:41 +0000 |
commit | 2f68e8bcc034e43b736b5d6789192f53fec88481 (patch) | |
tree | 360555bbd6800c3e583ecae19b0e459896958de5 /gcc/fold-const.c | |
parent | b8c03a9b391b02a6ace91b216e50926b49dbaae0 (diff) | |
download | gcc-2f68e8bcc034e43b736b5d6789192f53fec88481.zip gcc-2f68e8bcc034e43b736b5d6789192f53fec88481.tar.gz gcc-2f68e8bcc034e43b736b5d6789192f53fec88481.tar.bz2 |
fold-const.c (fold_binary_loc): Don't fold if the result is undefined.
* fold-const.c (fold_binary_loc): Don't fold if the result
is undefined.
* match.pd (A + (-B) -> A - B, A - (-B) -> A + B,
-(-A) -> A): Likewise.
* c-c++-common/ubsan/overflow-sub-4.c: New test.
* c-c++-common/ubsan/overflow-sub-2.c: Adjust dg-output.
* c-c++-common/ubsan/overflow-int128.c: Likewise.
From-SVN: r217427
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 82e2414..4321b1e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10538,6 +10538,9 @@ fold_binary_loc (location_t loc, /* A - B -> A + (-B) if B is easily negatable. */ if (negate_expr_p (arg1) + && (!INTEGRAL_TYPE_P (type) + || TYPE_OVERFLOW_WRAPS (type) + || (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0) && ((FLOAT_TYPE_P (type) /* Avoid this transformation if B is a positive REAL_CST. */ && (TREE_CODE (arg1) != REAL_CST |