@@ -977,18 +977,18 @@ 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(&int_ctype, range))
- base_type = &int_ctype;
else if (type_is_ok(&uint_ctype, range))
base_type = &uint_ctype;
- else if (type_is_ok(&long_ctype, range))
- base_type = &long_ctype;
+ else if (type_is_ok(&int_ctype, range))
+ base_type = &int_ctype;
else if (type_is_ok(&ulong_ctype, range))
base_type = &ulong_ctype;
- else if (type_is_ok(&llong_ctype, range))
- base_type = &llong_ctype;
+ else if (type_is_ok(&long_ctype, range))
+ base_type = &long_ctype;
else if (type_is_ok(&ullong_ctype, range))
base_type = &ullong_ctype;
+ else if (type_is_ok(&llong_ctype, range))
+ base_type = &llong_ctype;
else
base_type = &bad_ctype;
parent->ctype.base_type = base_type;
@@ -1,4 +1,4 @@
-enum e { OK };
+enum e { OK, KO = -1 };
typedef _Bool bool;
static int test(int i, long l, long long ll, enum e e, bool b, void *p)
@@ -13,7 +13,7 @@ static enum eb foo(enum ea a)
*
* check-error-start
enum-mismatch.c:7:16: warning: mixing different enum types
-enum-mismatch.c:7:16: int enum ea versus
-enum-mismatch.c:7:16: int enum eb
+enum-mismatch.c:7:16: unsigned int enum ea versus
+enum-mismatch.c:7:16: unsigned int enum eb
* check-error-end
*/
@@ -60,5 +60,4 @@ _Static_assert(is_unsigned(D) == 1, "enum D");
/*
* check-name: enum-sign-gcc
* check-command: sparse -m64 $file
- * check-known-to-fail
*/
GCC uses an unsigned type for enum's basetype unless one of the enumerators is negative. Using 'int' for plain simple enumerators and then using the same rule as for integer constants (int -> unsigned int -> long -> ...) should be more natural but doing so creates useless warnings when using sparse on the kernel code. So, do the same as GCC: * uses the smaller type that fits all enumerators, * uses at least int or unsigned int, * uses an signed type only if one of the enumerators is negative. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- parse.c | 12 ++++++------ validation/builtin-overflow.c | 2 +- validation/enum-mismatch.c | 4 ++-- validation/enum-sign-gcc.c | 1 - 4 files changed, 9 insertions(+), 10 deletions(-)