[PATCH 3/9] enum: fix cast_enum_list()

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

 



Sparse want that an enum's enumerators have all the same type.
This is done by first determining the common type and then
calling cast_enum_list() which use cast_value() on each member
to cast them to the common type.

However, cast_value() doesn't create a new expression and doesn't
change the ctype of the target: the target expression is supposed
to have already the right type and it's just the value that is
transfered from the source expression and size adjusted.
It's seems that in cast_enum_list() this has been overlooked
with the result that the value is correctly adjusted but keep
it's original type.

Fix this by updating, for each member, the desired type.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 parse.c                     | 1 +
 validation/enum-same-type.c | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/parse.c b/parse.c
index 32ccaa039..8b5f1a058 100644
--- a/parse.c
+++ b/parse.c
@@ -842,6 +842,7 @@ static void cast_enum_list(struct symbol_list *list, struct symbol *base_type)
 		if (expr->type != EXPR_VALUE)
 			continue;
 		ctype = expr->ctype;
+		expr->ctype = base_type;
 		if (ctype->bit_size == base_type->bit_size)
 			continue;
 		cast_value(expr, base_type, expr, ctype);
diff --git a/validation/enum-same-type.c b/validation/enum-same-type.c
index ac410a03a..0ff49cb45 100644
--- a/validation/enum-same-type.c
+++ b/validation/enum-same-type.c
@@ -11,5 +11,4 @@ _Static_assert([typeof(DUO)] == [typeof(NEG)], "enum same type");
 
 /*
  * check-name: enum-same-type
- * check-known-to-fail
  */
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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