[PATCH 5/5] bitfield: display the bitfield name in error messages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 parse.c                     |  9 +++------
 symbol.c                    |  3 ++-
 validation/bitfield-sizes.c | 10 +++++-----
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/parse.c b/parse.c
index efd8c5de1b6d..fb05253b6a4b 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
diff --git a/symbol.c b/symbol.c
index 40e50874c27f..3655cbb78913 100644
--- a/symbol.c
+++ b/symbol.c
@@ -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 c43bb0a4aeb2..9f76d07418a5 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
  */
-- 
2.24.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux