[PATCH 08/12] enum: use the values to determine the base type

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

 



The C standard requires that the type of enum constants is 'int'.
So a constant not representable as an int can't be used as the
the initializer of an enum. GCC extend this by using, instead
of 'int', the smallest type that can represent all the values
of the enum: first int, then unsigned int, long, ...
For sparse, we need to take in account the bitwise integers.

However, currently sparse doesn't do this based on the values
but on the type, so if one of the initializer is, for example,
1L, the base type is forced to a size as least as wide as 'long'.

Fix this by removing the call to bigger_enum_type().

Note that this is essentially a revert of commit
"51d3e7239: Make sure we keep enum values in a sufficiently large type for parsing"
which had the remark: "Make sure that the intermediate stages
keep the intermediate types big enough to cover the full range."
But this is not needed as during parsing, the values are kept at
full width and with their original type & value.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 parse.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/parse.c b/parse.c
index 9959c7aa0..34a70b447 100644
--- a/parse.c
+++ b/parse.c
@@ -832,19 +832,6 @@ static int type_is_ok(struct symbol *type, Num *upper, Num *lower)
 	return 0;
 }
 
-static struct symbol *bigger_enum_type(struct symbol *s1, struct symbol *s2)
-{
-	if (s1->bit_size < s2->bit_size) {
-		s1 = s2;
-	} else if (s1->bit_size == s2->bit_size) {
-		if (s2->ctype.modifiers & MOD_UNSIGNED)
-			s1 = s2;
-	}
-	if (s1->bit_size < bits_in_int)
-		return &int_ctype;
-	return s1;
-}
-
 static void cast_enum_list(struct symbol_list *list, struct symbol *base_type)
 {
 	struct symbol *sym;
@@ -927,7 +914,7 @@ static struct token *parse_enum_declaration(struct token *token, struct symbol *
 			} else if (ctype == base_type) {
 				/* nothing */
 			} else if (is_int_type(base_type) && is_int_type(ctype)) {
-				base_type = bigger_enum_type(base_type, ctype);
+				base_type = &int_ctype;
 			} else
 				base_type = &bad_ctype;
 			parent->ctype.base_type = base_type;
-- 
2.18.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