Skip to content

Commit

Permalink
shift_to_zero: silence some warnings inside macros
Browse files Browse the repository at this point in the history
There are a bunch of macros that do deliberate shifts to zero depending on
the .config.  Silence these warnings.

I'm not sure how practical and maintainable this check is...  It's
interesting to run it in private but I'm surprised I ever published this.

Signed-off-by: Dan Carpenter <[email protected]>
  • Loading branch information
error27 committed Mar 28, 2023
1 parent b707bb3 commit 60e88e6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion check_shift_to_zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static void match_binop2(struct expression *expr)
struct expression *left;
struct expression *tmp;
sval_t mask, shift;
char *macro, *inner;

if (expr->op != SPECIAL_RIGHTSHIFT)
return;
Expand All @@ -64,7 +65,20 @@ static void match_binop2(struct expression *expr)
if (mask.uvalue >> shift.uvalue)
return;

sm_warning("mask and shift to zero");
macro = get_macro_name(expr->pos);
inner = get_inner_macro(expr->pos);
if (macro && inner) {
if (strcmp(macro, "unlikely") == 0)
goto warn;
if (strcmp(inner, "unlikely") == 0 ||
strcmp(inner, "__const_hweight8") == 0 ||
strcmp(inner, "BITS_PER_LONG") == 0 ||
strcmp(inner, "CORDIC_PRECISION_SHIFT") == 0)
return;
}

warn:
sm_warning("mask and shift to zero: expr='%s'", expr_to_str(expr));
}

static void match_assign(struct expression *expr)
Expand Down

0 comments on commit 60e88e6

Please sign in to comment.