The predefined macros __SCHAR_MAX__, __SHRT_MAX__, __WCHAR_MAX__ & __CHAR_BIT__ are defined based on the size of these types on the machine where sparse was compiled. But since sparse has flags like -m32/-m64 and it's not unlikely to have one day a flag like -march=<some arch>, better to use the used by sparse for these types as stored in 'bits_in_char', 'bits_in_short', ... Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- lib.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib.c b/lib.c index 20eb72e95..99ecdcc4a 100644 --- a/lib.c +++ b/lib.c @@ -832,11 +832,16 @@ static void predefined_sizeof(const char *name, unsigned bits) add_pre_buffer("#weak_define __SIZEOF_%s__ %d\n", name, bits/8); } -static void predefined_type_size(const char *name, const char *suffix, unsigned bits) +static void predefined_max(const char *name, const char *suffix, unsigned bits) { unsigned long long max = (1ULL << (bits - 1 )) - 1; add_pre_buffer("#weak_define __%s_MAX__ %#llx%s\n", name, max, suffix); +} + +static void predefined_type_size(const char *name, const char *suffix, unsigned bits) +{ + predefined_max(name, suffix, bits); predefined_sizeof(name, bits); } @@ -845,6 +850,10 @@ static void predefined_macros(void) add_pre_buffer("#define __CHECKER__ 1\n"); predefined_sizeof("SHORT", bits_in_short); + predefined_max("SHRT", "", bits_in_short); + predefined_max("SCHAR", "", bits_in_char); + predefined_max("WCHAR", "", bits_in_wchar); + add_pre_buffer("#weak_define __CHAR_BIT__ %d\n", bits_in_char); predefined_type_size("INT", "", bits_in_int); predefined_type_size("LONG", "L", bits_in_long); @@ -1068,12 +1077,6 @@ void create_builtin_stream(void) add_pre_buffer("#define __OPTIMIZE__ 1\n"); if (optimize_size) add_pre_buffer("#define __OPTIMIZE_SIZE__ 1\n"); - - /* GCC defines these for limits.h */ - add_pre_buffer("#weak_define __SHRT_MAX__ " STRINGIFY(__SHRT_MAX__) "\n"); - add_pre_buffer("#weak_define __SCHAR_MAX__ " STRINGIFY(__SCHAR_MAX__) "\n"); - add_pre_buffer("#weak_define __WCHAR_MAX__ " STRINGIFY(__WCHAR_MAX__) "\n"); - add_pre_buffer("#weak_define __CHAR_BIT__ " STRINGIFY(__CHAR_BIT__) "\n"); } static struct symbol_list *sparse_tokenstream(struct token *token) -- 2.13.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