dexonsmith updated this revision to Diff 96078.
dexonsmith added a comment.

Here's an updated patch that uses `__SIZE_MAX__` and also handles the other 
pointer-like integers.

However, the first three static asserts fail, because `intptr_t` and 
`__INTPTR_TYPE__` are different types (same for `uintptr_t` and 
`__UINTPTR_TYPE__`).


https://reviews.llvm.org/D31856

Files:
  clang/lib/Headers/stdint.h
  clang/test/Headers/stdint-typeof-PTR_MIN-PTR_MAX.cpp
  clang/test/Preprocessor/stdint.c

Index: clang/test/Preprocessor/stdint.c
===================================================================
--- clang/test/Preprocessor/stdint.c
+++ clang/test/Preprocessor/stdint.c
@@ -74,9 +74,9 @@
 // ARM:INT_FAST64_MAX_ 9223372036854775807LL
 // ARM:UINT_FAST64_MAX_ 18446744073709551615ULL
 //
-// ARM:INTPTR_MIN_ (-2147483647 -1)
-// ARM:INTPTR_MAX_ 2147483647
-// ARM:UINTPTR_MAX_ 4294967295U
+// ARM:INTPTR_MIN_ (-2147483647L -1)
+// ARM:INTPTR_MAX_ 2147483647L
+// ARM:UINTPTR_MAX_ 4294967295UL
 // ARM:PTRDIFF_MIN_ (-2147483647 -1)
 // ARM:PTRDIFF_MAX_ 2147483647
 // ARM:SIZE_MAX_ 4294967295U
@@ -289,9 +289,9 @@
 // MIPS:INT_FAST64_MAX_ 9223372036854775807LL
 // MIPS:UINT_FAST64_MAX_ 18446744073709551615ULL
 //
-// MIPS:INTPTR_MIN_ (-2147483647 -1)
-// MIPS:INTPTR_MAX_ 2147483647
-// MIPS:UINTPTR_MAX_ 4294967295U
+// MIPS:INTPTR_MIN_ (-2147483647L -1)
+// MIPS:INTPTR_MAX_ 2147483647L
+// MIPS:UINTPTR_MAX_ 4294967295UL
 // MIPS:PTRDIFF_MIN_ (-2147483647 -1)
 // MIPS:PTRDIFF_MAX_ 2147483647
 // MIPS:SIZE_MAX_ 4294967295U
@@ -710,12 +710,12 @@
 // PPC64-NETBSD:INT_FAST64_MAX_ 9223372036854775807LL
 // PPC64-NETBSD:UINT_FAST64_MAX_ 18446744073709551615ULL
 //
-// PPC64-NETBSD:INTPTR_MIN_ (-9223372036854775807LL -1)
-// PPC64-NETBSD:INTPTR_MAX_ 9223372036854775807LL
-// PPC64-NETBSD:UINTPTR_MAX_ 18446744073709551615ULL
-// PPC64-NETBSD:PTRDIFF_MIN_ (-9223372036854775807LL -1)
-// PPC64-NETBSD:PTRDIFF_MAX_ 9223372036854775807LL
-// PPC64-NETBSD:SIZE_MAX_ 18446744073709551615ULL
+// PPC64-NETBSD:INTPTR_MIN_ (-9223372036854775807L -1)
+// PPC64-NETBSD:INTPTR_MAX_ 9223372036854775807L
+// PPC64-NETBSD:UINTPTR_MAX_ 18446744073709551615UL
+// PPC64-NETBSD:PTRDIFF_MIN_ (-9223372036854775807L -1)
+// PPC64-NETBSD:PTRDIFF_MAX_ 9223372036854775807L
+// PPC64-NETBSD:SIZE_MAX_ 18446744073709551615UL
 //
 // PPC64-NETBSD:INTMAX_MIN_ (-9223372036854775807LL -1)
 // PPC64-NETBSD:INTMAX_MAX_ 9223372036854775807LL
@@ -818,12 +818,12 @@
 // PPC:INT_FAST64_MAX_ 9223372036854775807LL
 // PPC:UINT_FAST64_MAX_ 18446744073709551615ULL
 //
-// PPC:INTPTR_MIN_ (-2147483647 -1)
-// PPC:INTPTR_MAX_ 2147483647
-// PPC:UINTPTR_MAX_ 4294967295U
-// PPC:PTRDIFF_MIN_ (-2147483647 -1)
-// PPC:PTRDIFF_MAX_ 2147483647
-// PPC:SIZE_MAX_ 4294967295U
+// PPC:INTPTR_MIN_ (-2147483647L -1)
+// PPC:INTPTR_MAX_ 2147483647L
+// PPC:UINTPTR_MAX_ 4294967295UL
+// PPC:PTRDIFF_MIN_ (-2147483647L -1)
+// PPC:PTRDIFF_MAX_ 2147483647L
+// PPC:SIZE_MAX_ 4294967295UL
 //
 // PPC:INTMAX_MIN_ (-9223372036854775807LL -1)
 // PPC:INTMAX_MAX_ 9223372036854775807LL
Index: clang/test/Headers/stdint-typeof-PTR_MIN-PTR_MAX.cpp
===================================================================
--- /dev/null
+++ clang/test/Headers/stdint-typeof-PTR_MIN-PTR_MAX.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s
+#include <stdint.h>
+#include <stddef.h>
+
+static_assert(__is_same(__typeof__(INTPTR_MIN), intptr_t),
+              "INTPTR_MIN should be intptr_t");
+static_assert(__is_same(__typeof__(INTPTR_MAX), intptr_t),
+              "INTPTR_MAX should be intptr_t");
+static_assert(__is_same(__typeof__(UINTPTR_MAX), uintptr_t),
+              "UINTPTR_MAX should be uintptr_t");
+static_assert(__is_same(__typeof__(PTRDIFF_MIN), ptrdiff_t),
+              "PTRDIFF_MIN should be ptrdiff_t");
+static_assert(__is_same(__typeof__(PTRDIFF_MAX), ptrdiff_t),
+              "PTRDIFF_MAX should be ptrdiff_t");
+static_assert(__is_same(__typeof__(SIZE_MAX), size_t),
+              "SIZE_MAX should be size_t");
Index: clang/lib/Headers/stdint.h
===================================================================
--- clang/lib/Headers/stdint.h
+++ clang/lib/Headers/stdint.h
@@ -659,12 +659,12 @@
 /* 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. */
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to