aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--expand.c5
-rw-r--r--lib.c4
-rw-r--r--lib.h2
-rw-r--r--simplify.c3
-rw-r--r--sparse.112
5 files changed, 25 insertions, 1 deletions
diff --git a/expand.c b/expand.c
index 5dace8e3..45e6f95e 100644
--- a/expand.c
+++ b/expand.c
@@ -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));
}
diff --git a/lib.c b/lib.c
index 308f8f69..2d87b567 100644
--- a/lib.c
+++ b/lib.c
@@ -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 },
diff --git a/lib.h b/lib.h
index b0453bb6..7362111c 100644
--- a/lib.h
+++ b/lib.h
@@ -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;
diff --git a/simplify.c b/simplify.c
index 19ff47a3..3a5ae933 100644
--- a/simplify.c
+++ b/simplify.c
@@ -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) {
diff --git a/sparse.1 b/sparse.1
index 806fb0cf..8a14a6be 100644
--- a/sparse.1
+++ b/sparse.1
@@ -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.