On Wed, 12 Nov 2014, Marek Polacek wrote: > This patch introduces TYPE_OVERFLOW_SANITIZED predicate to > consolidate a common check. > > Bootstrapped/regtested on x86_64-linux, ok for trunk?
Hmm, I'd have expected to test !TYPE_OVERFLOW_SANITIZED (), that is, have the predicate inverted. At least that's how I understand the name - an overflow is to be preserved for sanitization. So - can you invert the predicates (and uses)? In the sanitizer you then can guard instrumentations with TYPE_OVERFLOW_SANITIZED. Ok with that change. Thanks, Richard. > 2014-11-12 Marek Polacek <pola...@redhat.com> > > * tree.h (TYPE_OVERFLOW_SANITIZED): Define. > * fold-const.c (fold_binary_loc): Use it. > * match.pd: Likewise. > > diff --git gcc/fold-const.c gcc/fold-const.c > index 4321b1e..1fb48cc 100644 > --- gcc/fold-const.c > +++ gcc/fold-const.c > @@ -10538,9 +10538,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 gcc/match.pd gcc/match.pd > index d94a8f5..28298f4 100644 > --- gcc/match.pd > +++ 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 gcc/tree.h gcc/tree.h > index 0577d51..dc12bc6 100644 > --- gcc/tree.h > +++ gcc/tree.h > @@ -789,6 +789,13 @@ extern void omp_clause_range_check_failed (const_tree, > const char *, int, > #define TYPE_OVERFLOW_TRAPS(TYPE) \ > (!TYPE_UNSIGNED (TYPE) && flag_trapv) > > +/* True if it is possible to perform folding on TYPE wrt signed > + overflow. */ > +#define TYPE_OVERFLOW_SANITIZED(TYPE) \ > + (!INTEGRAL_TYPE_P (TYPE) \ > + || TYPE_OVERFLOW_WRAPS (TYPE) \ > + || (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0) > + > /* True if pointer types have undefined overflow. */ > #define POINTER_TYPE_OVERFLOW_UNDEFINED (flag_strict_overflow) > > > Marek > > -- Richard Biener <rguent...@suse.de> SUSE LINUX GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendoerffer, HRB 21284 (AG Nuernberg) Maxfeldstrasse 5, 90409 Nuernberg, Germany