Found when looking at something else. find_array_ref_with_const_idx_r would uselessly keep on looking for other array refs with constant indices, even though finding one is enough. So return when something is found, instead of just ignoring the subtrees.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-10-16 Marek Polacek <pola...@redhat.com> * c-warn.c (find_array_ref_with_const_idx_r): Remove parameter names. Return immediately when finding a match. (warn_tautological_cmp): Remove a boolean variable that is no longer needed. diff --git gcc/c-family/c-warn.c gcc/c-family/c-warn.c index 88544ce..904f6d3 100644 --- gcc/c-family/c-warn.c +++ gcc/c-family/c-warn.c @@ -256,17 +256,14 @@ warn_logical_operator (location_t location, enum tree_code code, tree type, with constant indices. */ static tree -find_array_ref_with_const_idx_r (tree *expr_p, int *walk_subtrees, void *data) +find_array_ref_with_const_idx_r (tree *expr_p, int *, void *) { tree expr = *expr_p; if ((TREE_CODE (expr) == ARRAY_REF || TREE_CODE (expr) == ARRAY_RANGE_REF) && TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST) - { - *(bool *) data = true; - *walk_subtrees = 0; - } + return integer_type_node; return NULL_TREE; } @@ -312,10 +309,8 @@ warn_tautological_cmp (location_t loc, enum tree_code code, tree lhs, tree rhs) { /* Don't warn about array references with constant indices; these are likely to come from a macro. */ - bool found = false; - walk_tree_without_duplicates (&lhs, find_array_ref_with_const_idx_r, - &found); - if (found) + if (walk_tree_without_duplicates (&lhs, find_array_ref_with_const_idx_r, + NULL)) return; const bool always_true = (code == EQ_EXPR || code == LE_EXPR || code == GE_EXPR || code == UNLE_EXPR Marek