This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

More stdint.h tests, fix c99-stdint-1.c bugs


The stdint.h tests allow limits of intptr_t and uintptr_t to be missing 
because those types are optional in C99.  However, the limits should be 
present if the types are.  Since GCC has an internal notion of whether the 
types should be present, we can test for whether this agrees with the 
header; this patch adds such a test.

The limits in stdint.h must be usable in #if conditions, so cannot contain 
casts; this patch adds a test of this requirement as well.

I also found some mistakes in c99-stdint-1.c for the cases where 
exact-width types are not present; these are fixed in this patch.

Tested on i686-pc-linux-gnu; applied to mainline.  The new c99-stdint-7.c 
should fail for newlib until 
<http://sourceware.org/ml/newlib/2009/msg00451.html> or a corresponding 
fixincludes patch is applied; the newlib bug motivates the addition of 
these tests.

Index: gcc.dg/c99-stdint-8.c
===================================================================
--- gcc.dg/c99-stdint-8.c	(revision 0)
+++ gcc.dg/c99-stdint-8.c	(revision 0)
@@ -0,0 +1,9 @@
+/* Verify that the limits defined in <stdint.h> are those GCC expects
+   internally to be defined and that they are usable in #if
+   conditions.  Freestanding version.  */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -ffreestanding" } */
+
+/* The test is that there are no diagnostics, so just include the
+   hosted version.  */
+#include "c99-stdint-7.c"
Index: gcc.dg/c99-stdint-1.c
===================================================================
--- gcc.dg/c99-stdint-1.c	(revision 145737)
+++ gcc.dg/c99-stdint-1.c	(working copy)
@@ -89,19 +89,19 @@
   CHECK_WIDTH_EQUALS(int16_t, 16);
   CHECK_SIGNED_LIMITS(int16_t, INT16_MIN, INT16_MAX);
 #else
-  CHECK_WIDTH_AT_LEAST(int_least8_t, 17);
+  CHECK_WIDTH_AT_LEAST(int_least16_t, 17);
 #endif
 #ifdef INT32_MIN
   CHECK_WIDTH_EQUALS(int32_t, 32);
   CHECK_SIGNED_LIMITS(int32_t, INT32_MIN, INT32_MAX);
 #else
-  CHECK_WIDTH_AT_LEAST(int_least8_t, 33);
+  CHECK_WIDTH_AT_LEAST(int_least32_t, 33);
 #endif
 #ifdef INT64_MIN
   CHECK_WIDTH_EQUALS(int64_t, 64);
   CHECK_SIGNED_LIMITS(int64_t, INT64_MIN, INT64_MAX);
 #else
-  CHECK_WIDTH_AT_LEAST(int_least8_t, 65);
+  CHECK_WIDTH_AT_LEAST(int_least64_t, 65);
 #endif
 #ifdef UINT8_MAX
   CHECK_WIDTH_EQUALS(uint8_t, 8);
@@ -113,19 +113,19 @@
   CHECK_WIDTH_EQUALS(uint16_t, 16);
   CHECK_UNSIGNED_LIMITS(uint16_t, UINT16_MAX);
 #else
-  CHECK_WIDTH_AT_LEAST(uint_least8_t, 17);
+  CHECK_WIDTH_AT_LEAST(uint_least16_t, 17);
 #endif
 #ifdef UINT32_MAX
   CHECK_WIDTH_EQUALS(uint32_t, 32);
   CHECK_UNSIGNED_LIMITS(uint32_t, UINT32_MAX);
 #else
-  CHECK_WIDTH_AT_LEAST(uint_least8_t, 33);
+  CHECK_WIDTH_AT_LEAST(uint_least32_t, 33);
 #endif
 #ifdef UINT64_MAX
   CHECK_WIDTH_EQUALS(uint64_t, 64);
   CHECK_UNSIGNED_LIMITS(uint64_t, UINT64_MAX);
 #else
-  CHECK_WIDTH_AT_LEAST(uint_least8_t, 65);
+  CHECK_WIDTH_AT_LEAST(uint_least64_t, 65);
 #endif
 }
 
Index: gcc.dg/c99-stdint-7.c
===================================================================
--- gcc.dg/c99-stdint-7.c	(revision 0)
+++ gcc.dg/c99-stdint-7.c	(revision 0)
@@ -0,0 +1,217 @@
+/* Verify that the limits defined in <stdint.h> are those GCC expects
+   internally to be defined and that they are usable in #if
+   conditions.  */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -fhosted" } */
+
+#include <stdint.h>
+
+/* Exact-width and pointer-holding types are optional.  */
+#if defined(INT8_MIN) != defined(__INT8_TYPE__)
+#error "Unexpected INT8_MIN definedness"
+#endif
+#if defined(INT8_MAX) != defined(__INT8_TYPE__)
+#error "Unexpected INT8_MAX definedness"
+#endif
+#if defined(UINT8_MAX) != defined(__UINT8_TYPE__)
+#error "Unexpected UINT8_MAX definedness"
+#endif
+#if defined(INT16_MIN) != defined(__INT16_TYPE__)
+#error "Unexpected INT16_MIN definedness"
+#endif
+#if defined(INT16_MAX) != defined(__INT16_TYPE__)
+#error "Unexpected INT16_MAX definedness"
+#endif
+#if defined(UINT16_MAX) != defined(__UINT16_TYPE__)
+#error "Unexpected UINT16_MAX definedness"
+#endif
+#if defined(INT32_MIN) != defined(__INT32_TYPE__)
+#error "Unexpected INT32_MIN definedness"
+#endif
+#if defined(INT32_MAX) != defined(__INT32_TYPE__)
+#error "Unexpected INT32_MAX definedness"
+#endif
+#if defined(UINT32_MAX) != defined(__UINT32_TYPE__)
+#error "Unexpected UINT32_MAX definedness"
+#endif
+#if defined(INT64_MIN) != defined(__INT64_TYPE__)
+#error "Unexpected INT64_MIN definedness"
+#endif
+#if defined(INT64_MAX) != defined(__INT64_TYPE__)
+#error "Unexpected INT64_MAX definedness"
+#endif
+#if defined(UINT64_MAX) != defined(__UINT64_TYPE__)
+#error "Unexpected UINT64_MAX definedness"
+#endif
+#if defined(INTPTR_MIN) != defined(__INTPTR_TYPE__)
+#error "Unexpected INTPTR_MIN definedness"
+#endif
+#if defined(INTPTR_MAX) != defined(__INTPTR_TYPE__)
+#error "Unexpected INTPTR_MAX definedness"
+#endif
+#if defined(UINTPTR_MAX) != defined(__UINTPTR_TYPE__)
+#error "Unexpected UINTPTR_MAX definedness"
+#endif
+
+#if defined(INT8_MIN) && INT8_MIN != -__INT8_MAX__-1
+#error "INT8_MIN not usable in #if or wrong value"
+#endif
+#if defined(INT8_MAX) && INT8_MAX != __INT8_MAX__
+#error "INT8_MAX not usable in #if or wrong value"
+#endif
+#if defined(UINT8_MAX) && UINT8_MAX != __UINT8_MAX__
+#error "UINT8_MAX not usable in #if or wrong value"
+#endif
+#if defined(INT16_MIN) && INT16_MIN != -__INT16_MAX__-1
+#error "INT16_MIN not usable in #if or wrong value"
+#endif
+#if defined(INT16_MAX) && INT16_MAX != __INT16_MAX__
+#error "INT16_MAX not usable in #if or wrong value"
+#endif
+#if defined(UINT16_MAX) && UINT16_MAX != __UINT16_MAX__
+#error "UINT16_MAX not usable in #if or wrong value"
+#endif
+#if defined(INT32_MIN) && INT32_MIN != -__INT32_MAX__-1
+#error "INT32_MIN not usable in #if or wrong value"
+#endif
+#if defined(INT32_MAX) && INT32_MAX != __INT32_MAX__
+#error "INT32_MAX not usable in #if or wrong value"
+#endif
+#if defined(UINT32_MAX) && UINT32_MAX != __UINT32_MAX__
+#error "UINT32_MAX not usable in #if or wrong value"
+#endif
+#if defined(INT64_MIN) && INT64_MIN != -__INT64_MAX__-1
+#error "INT64_MIN not usable in #if or wrong value"
+#endif
+#if defined(INT64_MAX) && INT64_MAX != __INT64_MAX__
+#error "INT64_MAX not usable in #if or wrong value"
+#endif
+#if defined(UINT64_MAX) && UINT64_MAX != __UINT64_MAX__
+#error "UINT64_MAX not usable in #if or wrong value"
+#endif
+
+#if INT_LEAST8_MIN != -__INT_LEAST8_MAX__-1
+#error "INT_LEAST8_MIN not usable in #if or wrong value"
+#endif
+#if INT_LEAST8_MAX != __INT_LEAST8_MAX__
+#error "INT_LEAST8_MAX not usable in #if or wrong value"
+#endif
+#if UINT_LEAST8_MAX != __UINT_LEAST8_MAX__
+#error "UINT_LEAST8_MAX not usable in #if or wrong value"
+#endif
+#if INT_LEAST16_MIN != -__INT_LEAST16_MAX__-1
+#error "INT_LEAST16_MIN not usable in #if or wrong value"
+#endif
+#if INT_LEAST16_MAX != __INT_LEAST16_MAX__
+#error "INT_LEAST16_MAX not usable in #if or wrong value"
+#endif
+#if UINT_LEAST16_MAX != __UINT_LEAST16_MAX__
+#error "UINT_LEAST16_MAX not usable in #if or wrong value"
+#endif
+#if INT_LEAST32_MIN != -__INT_LEAST32_MAX__-1
+#error "INT_LEAST32_MIN not usable in #if or wrong value"
+#endif
+#if INT_LEAST32_MAX != __INT_LEAST32_MAX__
+#error "INT_LEAST32_MAX not usable in #if or wrong value"
+#endif
+#if UINT_LEAST32_MAX != __UINT_LEAST32_MAX__
+#error "UINT_LEAST32_MAX not usable in #if or wrong value"
+#endif
+#if INT_LEAST64_MIN != -__INT_LEAST64_MAX__-1
+#error "INT_LEAST64_MIN not usable in #if or wrong value"
+#endif
+#if INT_LEAST64_MAX != __INT_LEAST64_MAX__
+#error "INT_LEAST64_MAX not usable in #if or wrong value"
+#endif
+#if UINT_LEAST64_MAX != __UINT_LEAST64_MAX__
+#error "UINT_LEAST64_MAX not usable in #if or wrong value"
+#endif
+
+#if INT_FAST8_MIN != -__INT_FAST8_MAX__-1
+#error "INT_FAST8_MIN not usable in #if or wrong value"
+#endif
+#if INT_FAST8_MAX != __INT_FAST8_MAX__
+#error "INT_FAST8_MAX not usable in #if or wrong value"
+#endif
+#if UINT_FAST8_MAX != __UINT_FAST8_MAX__
+#error "UINT_FAST8_MAX not usable in #if or wrong value"
+#endif
+#if INT_FAST16_MIN != -__INT_FAST16_MAX__-1
+#error "INT_FAST16_MIN not usable in #if or wrong value"
+#endif
+#if INT_FAST16_MAX != __INT_FAST16_MAX__
+#error "INT_FAST16_MAX not usable in #if or wrong value"
+#endif
+#if UINT_FAST16_MAX != __UINT_FAST16_MAX__
+#error "UINT_FAST16_MAX not usable in #if or wrong value"
+#endif
+#if INT_FAST32_MIN != -__INT_FAST32_MAX__-1
+#error "INT_FAST32_MIN not usable in #if or wrong value"
+#endif
+#if INT_FAST32_MAX != __INT_FAST32_MAX__
+#error "INT_FAST32_MAX not usable in #if or wrong value"
+#endif
+#if UINT_FAST32_MAX != __UINT_FAST32_MAX__
+#error "UINT_FAST32_MAX not usable in #if or wrong value"
+#endif
+#if INT_FAST64_MIN != -__INT_FAST64_MAX__-1
+#error "INT_FAST64_MIN not usable in #if or wrong value"
+#endif
+#if INT_FAST64_MAX != __INT_FAST64_MAX__
+#error "INT_FAST64_MAX not usable in #if or wrong value"
+#endif
+#if UINT_FAST64_MAX != __UINT_FAST64_MAX__
+#error "UINT_FAST64_MAX not usable in #if or wrong value"
+#endif
+
+#if defined(INTPTR_MIN) && INTPTR_MIN != -__INTPTR_MAX__-1
+#error "INTPTR_MIN not usable in #if or wrong value"
+#endif
+#if defined(INTPTR_MAX) && INTPTR_MAX != __INTPTR_MAX__
+#error "INTPTR_MAX not usable in #if or wrong value"
+#endif
+#if defined(UINTPTR_MAX) && UINTPTR_MAX != __UINTPTR_MAX__
+#error "UINTPTR_MAX not usable in #if or wrong value"
+#endif
+
+#if INTMAX_MIN != -__INTMAX_MAX__-1
+#error "INTMAX_MIN not usable in #if or wrong value"
+#endif
+#if INTMAX_MAX != __INTMAX_MAX__
+#error "INTMAX_MAX not usable in #if or wrong value"
+#endif
+#if UINTMAX_MAX != __UINTMAX_MAX__
+#error "UINTMAX_MAX not usable in #if or wrong value"
+#endif
+
+#if PTRDIFF_MIN != -__PTRDIFF_MAX__-1
+#error "PTRDIFF_MIN not usable in #if or wrong value"
+#endif
+#if PTRDIFF_MAX != __PTRDIFF_MAX__
+#error "PTRDIFF_MAX not usable in #if or wrong value"
+#endif
+
+#if SIG_ATOMIC_MIN != __SIG_ATOMIC_MIN__
+#error "SIG_ATOMIC_MIN not usable in #if or wrong value"
+#endif
+#if SIG_ATOMIC_MAX != __SIG_ATOMIC_MAX__
+#error "SIG_ATOMIC_MAX not usable in #if or wrong value"
+#endif
+
+#if SIZE_MAX != __SIZE_MAX__
+#error "SIZE_MAX not usable in #if or wrong value"
+#endif
+
+#if WCHAR_MIN != __WCHAR_MIN__
+#error "WCHAR_MIN not usable in #if or wrong value"
+#endif
+#if WCHAR_MAX != __WCHAR_MAX__
+#error "WCHAR_MAX not usable in #if or wrong value"
+#endif
+
+#if WINT_MIN != __WINT_MIN__
+#error "WINT_MIN not usable in #if or wrong value"
+#endif
+#if WINT_MAX != __WINT_MAX__
+#error "WINT_MAX not usable in #if or wrong value"
+#endif
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 145777)
+++ ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2009-04-08  Joseph Myers  <joseph@codesourcery.com>
+
+	* gcc.dg/c99-stdint-1.c: Fix cut-and-paste mistakes in test.
+	* gcc.dg/c99-stdint-7.c, gcc.dg/c99-stdint-8.c: New tests.
+
 2009-04-08  Jakub Jelinek  <jakub@redhat.com>
 
 	* g++.dg/debug/dwarf2/static-data-member1.C: New test.

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]