Skip to content

Commit

Permalink
precedence: add a warning for "foo & bar > baz"
Browse files Browse the repository at this point in the history
I haven't find any of these bugs in the kernel but it doesn't generate
any false positives either.

Signed-off-by: Dan Carpenter <[email protected]>
  • Loading branch information
Dan Carpenter committed Feb 26, 2019
1 parent 59c4322 commit 302ca03
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions check_precedence.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ static void match_mask(struct expression *expr)
sm_warning("shift has higher precedence than mask");
}

static void match_mask_compare(struct expression *expr)
{
if (expr->op != '&')
return;
if (expr->right->type != EXPR_COMPARE)
return;

sm_warning("compare has higher precedence than mask");
}

static void match_subtract_shift(struct expression *expr)
{
if (expr->op != SPECIAL_LEFTSHIFT)
Expand All @@ -138,5 +148,6 @@ void check_precedence(int id)
add_hook(&match_condition, CONDITION_HOOK);
add_hook(&match_binop, BINOP_HOOK);
add_hook(&match_mask, BINOP_HOOK);
add_hook(&match_mask_compare, BINOP_HOOK);
add_hook(&match_subtract_shift, BINOP_HOOK);
}

0 comments on commit 302ca03

Please sign in to comment.