diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-05-09 01:12:40 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-10-05 03:29:19 +0200 |
commit | acc13744b394d8de81709b8f61ebcfba81a270d3 (patch) | |
tree | 3b464e05e666f0392e3e35003956e4fd676f5468 | |
parent | 604a148a73af94bd271bbfb0d36dbe77e42bbc4f (diff) | |
download | sparse-acc13744b394d8de81709b8f61ebcfba81a270d3.tar.gz |
enum: use the smallest type that fit
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@gmail.com>
-rw-r--r-- | parse.c | 2 | ||||
-rw-r--r-- | validation/enum-base-type.c | 1 | ||||
-rw-r--r-- | validation/enum-bounds.c | 1 | ||||
-rw-r--r-- | validation/enum-min-size.c | 1 |
4 files changed, 0 insertions, 5 deletions
@@ -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 e430290b..cae801b1 100644 --- a/validation/enum-base-type.c +++ b/validation/enum-base-type.c @@ -26,5 +26,4 @@ _Static_assert(sizeof(enum p) == sizeof(int), "UL"); /* * check-name: enum-base-type * check-command: sparse -m64 $file - * check-known-to-fail */ diff --git a/validation/enum-bounds.c b/validation/enum-bounds.c index 604e0f33..64ecd8bb 100644 --- a/validation/enum-bounds.c +++ b/validation/enum-bounds.c @@ -21,5 +21,4 @@ _Static_assert([typeof(IMM2)] == [long], ""); /* * check-name: enum-bounds * check-command: sparse -m64 $file - * check-known-to-fail */ diff --git a/validation/enum-min-size.c b/validation/enum-min-size.c index 264a3154..e8bd9fb1 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 */ |