summaryrefslogtreecommitdiffstats
path: root/lib/Headers
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2017-04-27 21:49:45 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2017-04-27 21:49:45 +0000
commit7af3afd004e82e9303f02c2713d8cacd8215f1bd (patch)
treed733ae012ce128d589eb7907d088aa7d39ef6562 /lib/Headers
parentfc4c78381af3a65eb64567c94bac097b6b0246e4 (diff)
Headers: Make the type of SIZE_MAX the same as size_t
size_t is usually defined as unsigned long, but on 64-bit platforms, stdint.h currently defines SIZE_MAX using "ull" (unsigned long long). Although this is the same width, it doesn't necessarily have the same alignment or calling convention. It also triggers printf warnings when using the format flag "%zu" to print SIZE_MAX. This changes SIZE_MAX to reuse the compiler-provided __SIZE_MAX__, and provides similar fixes for the other integers: - INTPTR_MIN - INTPTR_MAX - UINTPTR_MAX - PTRDIFF_MIN - PTRDIFF_MAX - INTMAX_MIN - INTMAX_MAX - UINTMAX_MAX - INTMAX_C() - UINTMAX_C() ... and fixes the typedefs for intptr_t and uintptr_t to use __INTPTR_TYPE__ and __UINTPTR_TYPE__ instead of int32_t, effectively reverting r89224, r89226, and r89237 (r89221 already having been effectively reverted). We can probably also kill __INTPTR_WIDTH__, __INTMAX_WIDTH__, and __UINTMAX_WIDTH__ in a follow-up, but I was hesitant to delete all the per-target CHECK lines in this commit since those might serve their own purpose. rdar://problem/11811377 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301593 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Headers')
-rw-r--r--lib/Headers/stdint.h29
1 files changed, 13 insertions, 16 deletions
diff --git a/lib/Headers/stdint.h b/lib/Headers/stdint.h
index 3f2fcbc570..c48815314b 100644
--- a/lib/Headers/stdint.h
+++ b/lib/Headers/stdint.h
@@ -255,19 +255,16 @@ typedef __uint_least8_t uint_fast8_t;
*/
#define __stdint_join3(a,b,c) a ## b ## c
-#define __intn_t(n) __stdint_join3( int, n, _t)
-#define __uintn_t(n) __stdint_join3(uint, n, _t)
-
#ifndef _INTPTR_T
#ifndef __intptr_t_defined
-typedef __intn_t(__INTPTR_WIDTH__) intptr_t;
+typedef __INTPTR_TYPE__ intptr_t;
#define __intptr_t_defined
#define _INTPTR_T
#endif
#endif
#ifndef _UINTPTR_T
-typedef __uintn_t(__INTPTR_WIDTH__) uintptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
#define _UINTPTR_T
#endif
@@ -659,12 +656,12 @@ typedef __UINTMAX_TYPE__ uintmax_t;
/* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */
/* C99 7.18.3 Limits of other integer types. */
-#define INTPTR_MIN __INTN_MIN(__INTPTR_WIDTH__)
-#define INTPTR_MAX __INTN_MAX(__INTPTR_WIDTH__)
-#define UINTPTR_MAX __UINTN_MAX(__INTPTR_WIDTH__)
-#define PTRDIFF_MIN __INTN_MIN(__PTRDIFF_WIDTH__)
-#define PTRDIFF_MAX __INTN_MAX(__PTRDIFF_WIDTH__)
-#define SIZE_MAX __UINTN_MAX(__SIZE_WIDTH__)
+#define INTPTR_MIN (-__INTPTR_MAX__-1)
+#define INTPTR_MAX __INTPTR_MAX__
+#define UINTPTR_MAX __UINTPTR_MAX__
+#define PTRDIFF_MIN (-__PTRDIFF_MAX__-1)
+#define PTRDIFF_MAX __PTRDIFF_MAX__
+#define SIZE_MAX __SIZE_MAX__
/* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__
* is enabled. */
@@ -673,9 +670,9 @@ typedef __UINTMAX_TYPE__ uintmax_t;
#endif
/* C99 7.18.2.5 Limits of greatest-width integer types. */
-#define INTMAX_MIN __INTN_MIN(__INTMAX_WIDTH__)
-#define INTMAX_MAX __INTN_MAX(__INTMAX_WIDTH__)
-#define UINTMAX_MAX __UINTN_MAX(__INTMAX_WIDTH__)
+#define INTMAX_MIN (-__INTMAX_MAX__-1)
+#define INTMAX_MAX __INTMAX_MAX__
+#define UINTMAX_MAX __UINTMAX_MAX__
/* C99 7.18.3 Limits of other integer types. */
#define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__)
@@ -700,8 +697,8 @@ typedef __UINTMAX_TYPE__ uintmax_t;
#endif
/* 7.18.4.2 Macros for greatest-width integer constants. */
-#define INTMAX_C(v) __INTN_C(__INTMAX_WIDTH__, v)
-#define UINTMAX_C(v) __UINTN_C(__INTMAX_WIDTH__, v)
+#define INTMAX_C(v) __int_c(v, __INTMAX_C_SUFFIX__)
+#define UINTMAX_C(v) __int_c(v, __UINTMAX_C_SUFFIX__)
#endif /* __STDC_HOSTED__ */
#endif /* __CLANG_STDINT_H */