From 6a4f06787f9c0a9806a3f67a73dd12c33a8e8071 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 13 Nov 2014 10:17:51 +0000 Subject: [PATCH] tree.h (TYPE_OVERFLOW_SANITIZED): Define. * tree.h (TYPE_OVERFLOW_SANITIZED): Define. * fold-const.c (fold_binary_loc): Use it. * match.pd: Likewise. From-SVN: r217470 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 4 +--- gcc/match.pd | 12 +++--------- gcc/tree.h | 6 ++++++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 613208d3351..be3f64dad30 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-11-13 Marek Polacek + + * tree.h (TYPE_OVERFLOW_SANITIZED): Define. + * fold-const.c (fold_binary_loc): Use it. + * match.pd: Likewise. + 2014-11-14 Kirill Yukhin * gcc/lra-lives.c (struct bb_data): Rename to ... diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 2f32d3c9974..a711be9c106 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10516,9 +10516,7 @@ 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) + && !TYPE_OVERFLOW_SANITIZED (type) && ((FLOAT_TYPE_P (type) /* Avoid this transformation if B is a positive REAL_CST. */ && (TREE_CODE (arg1) != REAL_CST diff --git a/gcc/match.pd b/gcc/match.pd index 25711b68c68..5a423201183 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -285,26 +285,20 @@ along with GCC; see the file COPYING3. If not see /* Apply STRIP_NOPS on @0 and the negate. */ (if (tree_nop_conversion_p (type, TREE_TYPE (@0)) && tree_nop_conversion_p (type, TREE_TYPE (@1)) - && (!INTEGRAL_TYPE_P (type) - || TYPE_OVERFLOW_WRAPS (type) - || (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0)) + && !TYPE_OVERFLOW_SANITIZED (type)) (minus (convert @0) (convert @1)))) /* A - (-B) -> A + B */ (simplify (minus (convert1? @0) (convert2? (negate @1))) (if (tree_nop_conversion_p (type, TREE_TYPE (@0)) && tree_nop_conversion_p (type, TREE_TYPE (@1)) - && (!INTEGRAL_TYPE_P (type) - || TYPE_OVERFLOW_WRAPS (type) - || (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0)) + && !TYPE_OVERFLOW_SANITIZED (type)) (plus (convert @0) (convert @1)))) /* -(-A) -> A */ (simplify (negate (convert? (negate @1))) (if (tree_nop_conversion_p (type, TREE_TYPE (@1)) - && (!INTEGRAL_TYPE_P (type) - || TYPE_OVERFLOW_WRAPS (type) - || (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0)) + && !TYPE_OVERFLOW_SANITIZED (type)) (convert @1))) /* We can't reassociate floating-point or fixed-point plus or minus diff --git a/gcc/tree.h b/gcc/tree.h index 0577d51d1ca..108b52dcd68 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -789,6 +789,12 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, #define TYPE_OVERFLOW_TRAPS(TYPE) \ (!TYPE_UNSIGNED (TYPE) && flag_trapv) +/* True if an overflow is to be preserved for sanitization. */ +#define TYPE_OVERFLOW_SANITIZED(TYPE) \ + (INTEGRAL_TYPE_P (TYPE) \ + && !TYPE_OVERFLOW_WRAPS (TYPE) \ + && (flag_sanitize & SANITIZE_SI_OVERFLOW)) + /* True if pointer types have undefined overflow. */ #define POINTER_TYPE_OVERFLOW_UNDEFINED (flag_strict_overflow) -- 2.30.2