We need to strip away location wrappers in tree.c predicates like integer_zerop, otherwise they fail when they're called on wrapped INTEGER_CST; an example can be seen for c-c++-common/Wmemset-transposed-args1.c in g++.sum, where the warn_for_memset fails to detect integer zero if the location wrappers aren't stripped.
gcc/ChangeLog: * tree.c (integer_zerop): Use STRIP_ANY_LOCATION_WRAPPER on the expr. (integer_onep): Likewise. (integer_each_onep): Likewise. (integer_all_onesp): Likewise. (integer_minus_onep): Likewise. (integer_pow2p): Likewise. (integer_nonzerop): Likewise. (integer_truep): Likewise. (fixed_zerop): Likewise. (tree_log2): Likewise. (tree_floor_log2): Likewise. (tree_ctz): Likewise. (real_zerop): Likewise. (real_onep): Likewise. (real_minus_onep): Likewise. (really_constant_p): Likewise. --- gcc/tree.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gcc/tree.c b/gcc/tree.c index 50c818c..f71b484 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -2343,6 +2343,8 @@ zerop (const_tree expr) int integer_zerop (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + switch (TREE_CODE (expr)) { case INTEGER_CST: @@ -2369,6 +2371,8 @@ integer_zerop (const_tree expr) int integer_onep (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + switch (TREE_CODE (expr)) { case INTEGER_CST: @@ -2395,6 +2399,8 @@ integer_onep (const_tree expr) int integer_each_onep (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + if (TREE_CODE (expr) == COMPLEX_CST) return (integer_onep (TREE_REALPART (expr)) && integer_onep (TREE_IMAGPART (expr))); @@ -2408,6 +2414,8 @@ integer_each_onep (const_tree expr) int integer_all_onesp (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + if (TREE_CODE (expr) == COMPLEX_CST && integer_all_onesp (TREE_REALPART (expr)) && integer_all_onesp (TREE_IMAGPART (expr))) @@ -2434,6 +2442,8 @@ integer_all_onesp (const_tree expr) int integer_minus_onep (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + if (TREE_CODE (expr) == COMPLEX_CST) return (integer_all_onesp (TREE_REALPART (expr)) && integer_zerop (TREE_IMAGPART (expr))); @@ -2447,6 +2457,8 @@ integer_minus_onep (const_tree expr) int integer_pow2p (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + if (TREE_CODE (expr) == COMPLEX_CST && integer_pow2p (TREE_REALPART (expr)) && integer_zerop (TREE_IMAGPART (expr))) @@ -2464,6 +2476,8 @@ integer_pow2p (const_tree expr) int integer_nonzerop (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + return ((TREE_CODE (expr) == INTEGER_CST && wi::to_wide (expr) != 0) || (TREE_CODE (expr) == COMPLEX_CST @@ -2478,6 +2492,8 @@ integer_nonzerop (const_tree expr) int integer_truep (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + if (TREE_CODE (expr) == VECTOR_CST) return integer_all_onesp (expr); return integer_onep (expr); @@ -2488,6 +2504,8 @@ integer_truep (const_tree expr) int fixed_zerop (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + return (TREE_CODE (expr) == FIXED_CST && TREE_FIXED_CST (expr).data.is_zero ()); } @@ -2498,6 +2516,8 @@ fixed_zerop (const_tree expr) int tree_log2 (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + if (TREE_CODE (expr) == COMPLEX_CST) return tree_log2 (TREE_REALPART (expr)); @@ -2510,6 +2530,8 @@ tree_log2 (const_tree expr) int tree_floor_log2 (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + if (TREE_CODE (expr) == COMPLEX_CST) return tree_log2 (TREE_REALPART (expr)); @@ -2522,6 +2544,8 @@ tree_floor_log2 (const_tree expr) unsigned int tree_ctz (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)) && !POINTER_TYPE_P (TREE_TYPE (expr))) return 0; @@ -2633,6 +2657,8 @@ tree_ctz (const_tree expr) int real_zerop (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + switch (TREE_CODE (expr)) { case REAL_CST: @@ -2661,6 +2687,8 @@ real_zerop (const_tree expr) int real_onep (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + switch (TREE_CODE (expr)) { case REAL_CST: @@ -2688,6 +2716,8 @@ real_onep (const_tree expr) int real_minus_onep (const_tree expr) { + STRIP_ANY_LOCATION_WRAPPER (expr); + switch (TREE_CODE (expr)) { case REAL_CST: @@ -2714,6 +2744,8 @@ real_minus_onep (const_tree expr) int really_constant_p (const_tree exp) { + STRIP_ANY_LOCATION_WRAPPER (exp); + /* This is not quite the same as STRIP_NOPS. It does more. */ while (CONVERT_EXPR_P (exp) || TREE_CODE (exp) == NON_LVALUE_EXPR) -- 1.8.5.3