From 3f320159e32870bbba3b526da3290880bb15debc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 10 Oct 2019 12:04:26 -0700 Subject: [PATCH] c: improve patch for UCHAR_MAX etc. problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * data/skeletons/c.m4 (b4_c99_int_type_define): Reorder to put the signed types first, since they’re simpler and this keeps similar code closer. For signed types, don’t bother checking whether the type promotes to int since the type must be signed anyway. For unsigned types, protect a test like ‘UCHAR_MAX <= INT_MAX’ with ‘!defined __UINT_LEAST8_MAX__’, as otherwise the logic is wrong for oddball platforms; and once we do that, there should no need for ‘defined INT_MAX’ so remove that. --- data/skeletons/c.m4 | 50 +++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4 index 4c0f266b..586ee663 100644 --- a/data/skeletons/c.m4 +++ b/data/skeletons/c.m4 @@ -217,40 +217,42 @@ m4_define([b4_c99_int_type_define], save space and decrease cache pressure. Promoting to a signed type helps avoid bugs in integer arithmetic. */ -#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ -typedef __UINT_LEAST8_TYPE__ yytype_uint8; -#elif defined UINT_LEAST8_MAX && defined INT_MAX && UINT_LEAST8_MAX <= INT_MAX -typedef uint_least8_t yytype_uint8; -#elif defined UCHAR_MAX && defined INT_MAX && UCHAR_MAX <= INT_MAX -typedef unsigned char yytype_uint8; -#else -typedef short yytype_uint8; -#endif - -#if defined __INT_LEAST8_MAX__ && __INT_LEAST8_MAX__ <= __INT_MAX__ +#ifdef __INT_LEAST8_MAX__ typedef __INT_LEAST8_TYPE__ yytype_int8; -#elif defined INT_LEAST8_MAX && defined INT_MAX && INT_LEAST8_MAX <= INT_MAX +#elif defined INT_LEAST8_MAX typedef int_least8_t yytype_int8; #else typedef signed char yytype_int8; #endif -#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ -typedef __UINT_LEAST16_TYPE__ yytype_uint16; -#elif defined UINT_LEAST16_MAX && defined INT_MAX && UINT_LEAST16_MAX <= INT_MAX -typedef uint_least16_t yytype_uint16; -#elif defined USHRT_MAX && defined INT_MAX && USHRT_MAX <= INT_MAX -typedef unsigned short yytype_uint16; -#else -typedef int yytype_uint16; -#endif - -#if defined __INT_LEAST16_MAX__ && __INT_LEAST16_MAX__ <= __INT_MAX__ +#ifdef __INT_LEAST16_MAX__ typedef __INT_LEAST16_TYPE__ yytype_int16; -#elif defined INT_LEAST16_MAX && defined INT_MAX && INT_LEAST16_MAX <= INT_MAX +#elif defined INT_LEAST16_MAX typedef int_least16_t yytype_int16; #else typedef short yytype_int16; +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined UINT_LEAST8_MAX \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined UINT_LEAST16_MAX \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; #endif]])