Some small improvements to the builtin (-ffreestanding) stdint.h; in

particular, make sure to handle WCHAR_MIN correctly.

llvm-svn: 130618
This commit is contained in:
Eli Friedman 2011-04-30 19:02:59 +00:00
parent 6a10ed51c0
commit fe0739dffb
2 changed files with 21 additions and 13 deletions

View File

@ -609,11 +609,15 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define UINT_FAST8_MAX __UINT_LEAST8_MAX
#endif /* __INT_LEAST8_MIN */
/* Some utility macros */
#define __INTN_MIN(n) __stdint_join3( INT, n, _MIN)
#define __INTN_MAX(n) __stdint_join3( INT, n, _MAX)
#define __UINTN_MAX(n) __stdint_join3(UINT, n, _MAX)
#define __INTN_C(n, v) __stdint_join3( INT, n, _C(v))
#define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v))
/* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */
/* C99 7.18.3 Limits of other integer types. */
#define __INTN_MIN(n) __stdint_join3( INT, n, _MIN)
#define __INTN_MAX(n) __stdint_join3( INT, n, _MAX)
#define __UINTN_MAX(n) __stdint_join3(UINT, n, _MAX)
#define INTPTR_MIN __INTN_MIN(__INTPTR_WIDTH__)
#define INTPTR_MAX __INTN_MAX(__INTPTR_WIDTH__)
@ -631,27 +635,25 @@ typedef __UINTMAX_TYPE__ uintmax_t;
#define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__)
#define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__)
#ifdef __WINT_UNSIGNED__
# define WINT_MIN 0
# define WINT_MIN __UINTN_C(__WINT_WIDTH__, 0)
# define WINT_MAX __UINTN_MAX(__WINT_WIDTH__)
#else
# define WINT_MIN __INTN_MIN(__WINT_WIDTH__)
# define WINT_MAX __INTN_MAX(__WINT_WIDTH__)
#endif
/* FIXME: if we ever support a target with unsigned wchar_t, this should be
* 0 .. Max.
*/
#ifndef WCHAR_MAX
#define WCHAR_MAX __INTN_MAX(__WCHAR_WIDTH__)
# define WCHAR_MAX __WCHAR_MAX__
#endif
#ifndef WCHAR_MIN
#define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__)
# if __WCHAR_MAX__ == __INTN_MAX(__WCHAR_WIDTH__)
# define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__)
# else
# define WCHAR_MIN __UINTN_C(__WCHAR_WIDTH__, 0)
# endif
#endif
/* 7.18.4.2 Macros for greatest-width integer constants. */
#define __INTN_C(n, v) __stdint_join3( INT, n, _C(v))
#define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v))
#define INTMAX_C(v) __INTN_C(__INTMAX_WIDTH__, v)
#define UINTMAX_C(v) __UINTN_C(__INTMAX_WIDTH__, v)

View File

@ -1061,10 +1061,16 @@
//
// RUN: %clang_cc1 -E -ffreestanding -triple=x86_64-pc-linux-gnu %s | FileCheck -check-prefix X86_64_LINUX %s
//
// X86_64_LINUX:WINT_MIN_ 0
// X86_64_LINUX:WINT_MIN_ 0U
// X86_64_LINUX:WINT_MAX_ 4294967295U
//
//
// RUN: %clang_cc1 -E -ffreestanding -triple=i386-mingw32 %s | FileCheck -check-prefix I386_MINGW32 %s
//
// I386_MINGW32:WCHAR_MAX_ 65535U
// I386_MINGW32:WCHAR_MIN_ 0U
//
//
// stdint.h forms several macro definitions by pasting together identifiers
// to form names (eg. int32_t is formed from int ## 32 ## _t). The following
// case tests that these joining operations are performed correctly even if