diff options
| -rw-r--r-- | expand.c | 5 | ||||
| -rw-r--r-- | lib.c | 4 | ||||
| -rw-r--r-- | lib.h | 2 | ||||
| -rw-r--r-- | simplify.c | 3 | ||||
| -rw-r--r-- | sparse.1 | 12 |
5 files changed, 25 insertions, 1 deletions
@@ -164,6 +164,8 @@ static void check_shift_count(struct expression *expr, struct expression *right) long long count = get_longlong(right); if (count < 0) { + if (!Wshift_count_negative) + return; warning(expr->pos, "shift count is negative (%lld)", count); return; } @@ -171,6 +173,9 @@ static void check_shift_count(struct expression *expr, struct expression *right) return; if (ctype->type == SYM_NODE) ctype = ctype->ctype.base_type; + + if (!Wshift_count_overflow) + return; warning(expr->pos, "shift too big (%llu) for type %s", count, show_typename(ctype)); } @@ -274,6 +274,8 @@ int Wpointer_to_int_cast = 1; int Wptr_subtraction_blows = 0; int Wreturn_void = 0; int Wshadow = 0; +int Wshift_count_negative = 1; +int Wshift_count_overflow = 1; int Wsizeof_bool = 0; int Wtautological_compare = 0; int Wtransparent_union = 0; @@ -701,6 +703,8 @@ static const struct flag warnings[] = { { "ptr-subtraction-blows", &Wptr_subtraction_blows }, { "return-void", &Wreturn_void }, { "shadow", &Wshadow }, + { "shift-count-negative", &Wshift_count_negative }, + { "shift-count-overflow", &Wshift_count_overflow }, { "sizeof-bool", &Wsizeof_bool }, { "pointer-arith", &Wpointer_arith }, { "sparse-error", &Wsparse_error }, @@ -163,6 +163,8 @@ extern int Wpointer_to_int_cast; extern int Wptr_subtraction_blows; extern int Wreturn_void; extern int Wshadow; +extern int Wshift_count_negative; +extern int Wshift_count_overflow; extern int Wsizeof_bool; extern int Wtautological_compare; extern int Wtransparent_union; @@ -549,7 +549,8 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v size = insn->size; if (value >= size && !insn->tainted) { - warning(insn->pos, "shift by bigger than operand's width"); + if (Wshift_count_overflow) + warning(insn->pos, "shift by bigger than operand's width"); insn->tainted = 1; } switch (insn->opcode) { @@ -339,6 +339,18 @@ Such declarations can lead to error-prone code. Sparse does not issue these warnings by default. . .TP +.B \-Wshift-count-negative +Warn if a shift count is negative. + +Sparse issues these warnings by default. +. +.TP +.B \-Wshift-count-overflow +Warn if a shift count is bigger than the operand's width. + +Sparse issues these warnings by default. +. +.TP .B \-Wsizeof-bool Warn when checking the sizeof a _Bool. |
