[PATCH 07/12] enum: use the smallest type that fit

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

 



The C standard requires that the type of enum constants is 'int'
and let the enum base/compatible type be implementation defined.
For this base type, instead of 'int', GCC uses the smallest type
that can represent all the values of the enum (int, unsigned int,
long, ...)

Sparse has the same logic as GCC but if all the initializers
have the same type, this type is used instead.
This is a sensible choice but often gives differents
result than GCC.

To stay more compatible with GCC, always use the same logic
and thus only keep the common type as base type for restricted
types.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 parse.c                     | 2 --
 validation/enum-base-type.c | 1 -
 validation/enum-bounds.c    | 1 -
 validation/enum-min-size.c  | 1 -
 4 files changed, 5 deletions(-)

diff --git a/parse.c b/parse.c
index 2a448f45d..9959c7aa0 100644
--- a/parse.c
+++ b/parse.c
@@ -957,8 +957,6 @@ static struct token *parse_enum_declaration(struct token *token, struct symbol *
 	}
 	else if (!is_int_type(base_type))
 		base_type = base_type;
-	else if (type_is_ok(base_type, &upper, &lower))
-		base_type = base_type;
 	else if (type_is_ok(&int_ctype, &upper, &lower))
 		base_type = &int_ctype;
 	else if (type_is_ok(&uint_ctype, &upper, &lower))
diff --git a/validation/enum-base-type.c b/validation/enum-base-type.c
index ecec59296..f9509edc7 100644
--- a/validation/enum-base-type.c
+++ b/validation/enum-base-type.c
@@ -25,5 +25,4 @@ _Static_assert(sizeof(enum p) == sizeof(int), "UL");
 
 /*
  * check-name: enum-base-type
- * check-known-to-fail
  */
diff --git a/validation/enum-bounds.c b/validation/enum-bounds.c
index d8993edb4..07807dbc3 100644
--- a/validation/enum-bounds.c
+++ b/validation/enum-bounds.c
@@ -20,5 +20,4 @@ _Static_assert([typeof(IMM2)] == [long], "");
 
 /*
  * check-name: enum-bounds
- * check-known-to-fail
  */
diff --git a/validation/enum-min-size.c b/validation/enum-min-size.c
index 264a31542..e8bd9fb1b 100644
--- a/validation/enum-min-size.c
+++ b/validation/enum-min-size.c
@@ -26,5 +26,4 @@ _Static_assert(sizeof(enum n) == sizeof(int), "llong");
 
 /*
  * check-name: enum-min-size
- * check-known-to-fail
  */
-- 
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