diff options
| -rw-r--r-- | evaluate.c | 19 | ||||
| -rw-r--r-- | lib.c | 2 | ||||
| -rw-r--r-- | lib.h | 1 | ||||
| -rw-r--r-- | sparse.1 | 6 | ||||
| -rw-r--r-- | validation/bitwise-cast-ptr.c | 3 |
5 files changed, 29 insertions, 2 deletions
@@ -3045,6 +3045,25 @@ static struct symbol *evaluate_cast(struct expression *expr) if (ttype == &bool_ctype) cast_to_bool(expr); + // checks pointers to restricted + while (Wbitwise_pointer && tclass == TYPE_PTR && sclass == TYPE_PTR) { + tclass = classify_type(ttype->ctype.base_type, &ttype); + sclass = classify_type(stype->ctype.base_type, &stype); + if (ttype == stype) + break; + if (!ttype || !stype) + break; + if (ttype == &void_ctype || stype == &void_ctype) + break; + if (tclass & TYPE_RESTRICT) { + warning(expr->pos, "cast to %s", show_typename(ctype)); + break; + } + if (sclass & TYPE_RESTRICT) { + warning(expr->pos, "cast from %s", show_typename(source->ctype)); + break; + } + } out: return ctype; } @@ -251,6 +251,7 @@ static struct token *pre_buffer_end = NULL; int Waddress = 0; int Waddress_space = 1; int Wbitwise = 1; +int Wbitwise_pointer = 0; int Wcast_from_as = 0; int Wcast_to_as = 0; int Wcast_truncate = 1; @@ -692,6 +693,7 @@ static const struct flag warnings[] = { { "address", &Waddress }, { "address-space", &Waddress_space }, { "bitwise", &Wbitwise }, + { "bitwise-pointer", &Wbitwise_pointer}, { "cast-from-as", &Wcast_from_as }, { "cast-to-as", &Wcast_to_as }, { "cast-truncate", &Wcast_truncate }, @@ -139,6 +139,7 @@ extern int preprocess_only; extern int Waddress; extern int Waddress_space; extern int Wbitwise; +extern int Wbitwise_pointer; extern int Wcast_from_as; extern int Wcast_to_as; extern int Wcast_truncate; @@ -77,6 +77,12 @@ Sparse issues these warnings by default. To turn them off, use \fB\-Wno\-bitwise\fR. . .TP +.B \-Wbitwise\-pointer +Same as \fB\-Wbitwise\fR but for casts to or from pointers to bitwise types. + +Sparse does not issue these warnings by default. +. +.TP .B \-Wcast\-from\-as Warn about which remove an address space to a pointer type. diff --git a/validation/bitwise-cast-ptr.c b/validation/bitwise-cast-ptr.c index acf0ac35..3f2bfdaf 100644 --- a/validation/bitwise-cast-ptr.c +++ b/validation/bitwise-cast-ptr.c @@ -22,8 +22,7 @@ static __be32* tobf(u32 *x) /* * check-name: cast of bitwise pointers - * check-command: sparse -Wbitwise $file - * check-known-to-fail + * check-command: sparse -Wbitwise -Wbitwise-pointer $file * * check-error-start bitwise-cast-ptr.c:9:16: warning: incorrect type in return expression (different base types) |
