diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-10-01 22:35:42 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-30 14:05:03 +0100 |
commit | 38dfaa85aef4f1f02f114dffeda02c818d87fe06 (patch) | |
tree | 9e58b70bcf3232ef218a98cc5e7547e0c586f433 | |
parent | b187d1bbd61f49fd8008be7091a13df5600bcea6 (diff) | |
download | sparse-38dfaa85aef4f1f02f114dffeda02c818d87fe06.tar.gz |
bitfield: display the bitfield name in error messages
Diagnostics related to a bitfield and issued after parsing
didn't display the bitfield name because it was not available.
Now that that the name is available, use it in error messages
since it helps to find the origin of the problem.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | parse.c | 9 | ||||
-rw-r--r-- | symbol.c | 3 | ||||
-rw-r--r-- | validation/bitfield-sizes.c | 10 |
3 files changed, 10 insertions, 12 deletions
@@ -1946,12 +1946,9 @@ static struct token *handle_bitfield(struct token *token, struct decl_state *ctx width = const_expression_value(expr); bitfield->bit_size = width; - if (width < 0 || width > INT_MAX) { - sparse_error(token->pos, "invalid bitfield width, %lld.", width); - width = -1; - } else if (*ctx->ident && width == 0) { - sparse_error(token->pos, "invalid named zero-width bitfield `%s'", - show_ident(*ctx->ident)); + if (width < 0 || width > INT_MAX || (*ctx->ident && width == 0)) { + sparse_error(token->pos, "bitfield '%s' has invalid width (%lld)", + show_ident(*ctx->ident), width); width = -1; } else if (*ctx->ident) { struct symbol *base_type = bitfield->ctype.base_type; @@ -259,7 +259,8 @@ static struct symbol *examine_bitfield_type(struct symbol *sym) if (!base_type) return sym; if (sym->bit_size > base_type->bit_size) { - sparse_error(sym->pos, "impossible field-width, %d, for this type", sym->bit_size); + sparse_error(sym->pos, "bitfield '%s' is wider (%d) than its type (%s)", + show_ident(sym->ident), sym->bit_size, show_typename(base_type)); sym->bit_size = -1; } diff --git a/validation/bitfield-sizes.c b/validation/bitfield-sizes.c index c43bb0a4..9f76d074 100644 --- a/validation/bitfield-sizes.c +++ b/validation/bitfield-sizes.c @@ -21,10 +21,10 @@ static struct b b; * check-command: sparse -m64 $file * * check-error-start -bitfield-sizes.c:12:18: error: invalid bitfield width, -1. -bitfield-sizes.c:13:26: error: invalid bitfield width, 2147483648. -bitfield-sizes.c:15:17: error: invalid named zero-width bitfield `a0' -bitfield-sizes.c:6:15: error: impossible field-width, 33, for this type -bitfield-sizes.c:7:15: error: impossible field-width, 65, for this type +bitfield-sizes.c:12:18: error: bitfield 'm1' has invalid width (-1) +bitfield-sizes.c:13:26: error: bitfield 'x1' has invalid width (2147483648) +bitfield-sizes.c:15:17: error: bitfield 'a0' has invalid width (0) +bitfield-sizes.c:6:15: error: bitfield 'x' is wider (33) than its type (int) +bitfield-sizes.c:7:15: error: bitfield 'y' is wider (65) than its type (long) * check-error-end */ |