From: Joseph Myers Date: Thu, 5 Aug 2004 00:38:31 +0000 (+0100) Subject: c-common.c (c_stddef_cpp_builtins): Define __INTMAX_TYPE__ and __UINTMAX_TYPE__. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=852910694f6d4480afd733a62fd6b93de62b51e6;p=gcc.git c-common.c (c_stddef_cpp_builtins): Define __INTMAX_TYPE__ and __UINTMAX_TYPE__. * c-common.c (c_stddef_cpp_builtins): Define __INTMAX_TYPE__ and __UINTMAX_TYPE__. * c-cppbuiltin.c (builtin_define_stdint_macros): New. Define __INTMAX_MAX__. (c_cpp_builtins): Call it. * doc/cpp.texi: Update. testsuite: * gcc.c-torture/execute/builtins/abs-2.c, gcc.c-torture/execute/builtins/abs-3.c, gcc.c-torture/execute/builtins/lib/abs.c, gcc.dg/format/format.h, gcc.dg/torture/builtin-attr-1.c: Use predefined macros for intmax_t, uintmax_t and their limits. * gcc.dg/intmax_t-1.c: New test. From-SVN: r85588 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e480dd1e095..761abf8218b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2004-08-05 Joseph S. Myers + + * c-common.c (c_stddef_cpp_builtins): Define __INTMAX_TYPE__ and + __UINTMAX_TYPE__. + * c-cppbuiltin.c (builtin_define_stdint_macros): New. Define + __INTMAX_MAX__. + (c_cpp_builtins): Call it. + * doc/cpp.texi: Update. + 2004-08-04 David Edelsohn * config/rs6000/rs6000.c (rs6000_rtx_costs): LABEL_REFs are zero diff --git a/gcc/c-common.c b/gcc/c-common.c index 30d96e6223b..b0f23a2c1a3 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -3883,6 +3883,8 @@ c_stddef_cpp_builtins(void) builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0); builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0); builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0); + builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0); + builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0); } static void diff --git a/gcc/c-cppbuiltin.c b/gcc/c-cppbuiltin.c index 441a38e3b8c..f6a1805f0b8 100644 --- a/gcc/c-cppbuiltin.c +++ b/gcc/c-cppbuiltin.c @@ -54,6 +54,7 @@ static void builtin_define_with_int_value (const char *, HOST_WIDE_INT); static void builtin_define_with_hex_fp_value (const char *, tree, int, const char *, const char *); +static void builtin_define_stdint_macros (void); static void builtin_define_type_max (const char *, tree, int); static void builtin_define_type_precision (const char *, tree); static void builtin_define_float_constants (const char *, const char *, @@ -293,6 +294,23 @@ define__GNUC__ (void) abort (); } +/* Define macros used by . Currently only defines limits + for intmax_t, used by the testsuite. */ +static void +builtin_define_stdint_macros (void) +{ + int intmax_long; + if (intmax_type_node == long_long_integer_type_node) + intmax_long = 2; + else if (intmax_type_node == long_integer_type_node) + intmax_long = 1; + else if (intmax_type_node == integer_type_node) + intmax_long = 0; + else + abort (); + builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node, intmax_long); +} + /* Hook that registers front end and target-specific built-ins. */ void c_cpp_builtins (cpp_reader *pfile) @@ -354,6 +372,9 @@ c_cpp_builtins (cpp_reader *pfile) builtin_define_type_precision ("__CHAR_BIT__", char_type_node); + /* stdint.h (eventually) and the testsuite need to know these. */ + builtin_define_stdint_macros (); + /* float.h needs to know these. */ builtin_define_with_int_value ("__FLT_EVAL_METHOD__", diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index 631992d5173..c047c570f71 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -2053,8 +2053,11 @@ OSF/rose @option{-mno-underscores} option). @itemx __PTRDIFF_TYPE__ @itemx __WCHAR_TYPE__ @itemx __WINT_TYPE__ +@itemx __INTMAX_TYPE__ +@itemx __UINTMAX_TYPE__ These macros are defined to the correct underlying types for the -@code{size_t}, @code{ptrdiff_t}, @code{wchar_t}, and @code{wint_t} +@code{size_t}, @code{ptrdiff_t}, @code{wchar_t}, @code{wint_t}, +@code{intmax_t}, and @code{uintmax_t} typedefs, respectively. They exist to make the standard header files @file{stddef.h} and @file{wchar.h} work correctly. You should not use these macros directly; instead, include the appropriate headers and use @@ -2072,9 +2075,11 @@ this macro directly; instead, include the appropriate headers. @itemx __INT_MAX__ @itemx __LONG_MAX__ @itemx __LONG_LONG_MAX__ +@itemx __INTMAX_MAX__ Defined to the maximum value of the @code{signed char}, @code{wchar_t}, @code{signed short}, -@code{signed int}, @code{signed long}, and @code{signed long long} types +@code{signed int}, @code{signed long}, @code{signed long long}, and +@code{intmax_t} types respectively. They exist to make the standard header given numerical limits work correctly. You should not use these macros directly; instead, include the appropriate headers. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 788e6955d6e..c42117a238a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2004-08-05 Joseph S. Myers + + * gcc.c-torture/execute/builtins/abs-2.c, + gcc.c-torture/execute/builtins/abs-3.c, + gcc.c-torture/execute/builtins/lib/abs.c, gcc.dg/format/format.h, + gcc.dg/torture/builtin-attr-1.c: Use predefined macros for + intmax_t, uintmax_t and their limits. + * gcc.dg/intmax_t-1.c: New test. + 2004-08-04 Giovanni Bajo * g++.dg/tc1/dr147.C: Add reference to PR. diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2.c index 025488d7dd8..c13c4556eca 100644 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2.c +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2.c @@ -1,20 +1,9 @@ /* Test for builtin abs, labs, llabs, imaxabs. */ /* Origin: Joseph Myers */ -/* These next definitions are kludges. When GCC has a it - should be used. -*/ #include -#if INT_MAX == __LONG_LONG_MAX__ -typedef int intmax_t; -#define INTMAX_MAX INT_MAX -#elif LONG_MAX == __LONG_LONG_MAX__ -typedef long intmax_t; -#define INTMAX_MAX LONG_MAX -#else -typedef long long intmax_t; -#define INTMAX_MAX __LONG_LONG_MAX__ -#endif +typedef __INTMAX_TYPE__ intmax_t; +#define INTMAX_MAX __INTMAX_MAX__ extern int abs (int); extern long labs (long); diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3.c b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3.c index 8300a48a64a..cb0d89eb0ef 100644 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3.c +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3.c @@ -1,20 +1,9 @@ /* Test for builtin abs, labs, llabs, imaxabs. Test for __builtin versions. */ /* Origin: Joseph Myers */ -/* These next definitions are kludges. When GCC has a it - should be used. -*/ #include -#if INT_MAX == __LONG_LONG_MAX__ -typedef int intmax_t; -#define INTMAX_MAX INT_MAX -#elif LONG_MAX == __LONG_LONG_MAX__ -typedef long intmax_t; -#define INTMAX_MAX LONG_MAX -#else -typedef long long intmax_t; -#define INTMAX_MAX __LONG_LONG_MAX__ -#endif +typedef __INTMAX_TYPE__ intmax_t; +#define INTMAX_MAX __INTMAX_MAX__ extern void abort (void); extern void link_error (void); diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c index 99ca10df393..590ded7892b 100644 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c @@ -6,20 +6,7 @@ extern void abort (void); #define ABORT_INSIDE_MAIN do { } while (0) #endif -/* These next definitions are kludges. When GCC has a it - should be used. -*/ -#include -#if INT_MAX == __LONG_LONG_MAX__ -typedef int intmax_t; -#define INTMAX_MAX INT_MAX -#elif LONG_MAX == __LONG_LONG_MAX__ -typedef long intmax_t; -#define INTMAX_MAX LONG_MAX -#else -typedef long long intmax_t; -#define INTMAX_MAX __LONG_LONG_MAX__ -#endif +typedef __INTMAX_TYPE__ intmax_t; int abs (int x) diff --git a/gcc/testsuite/gcc.dg/format/format.h b/gcc/testsuite/gcc.dg/format/format.h index 230d1410136..0ded1e0382a 100644 --- a/gcc/testsuite/gcc.dg/format/format.h +++ b/gcc/testsuite/gcc.dg/format/format.h @@ -28,31 +28,8 @@ __extension__ typedef unsigned long long int ullong; typedef llong quad_t; typedef ullong u_quad_t; -/* This next definition is a kludge. When GCC has a it - should be used. -*/ -/* (T *) if E is zero, (void *) otherwise. */ -#define type_if_not(T, E) __typeof__(0 ? (T *)0 : (void *)(E)) - -/* (T *) if E is nonzero, (void *) otherwise. */ -#define type_if(T, E) type_if_not(T, !(E)) - -/* Combine pointer types, all but one (void *). */ -#define type_comb2(T1, T2) __typeof__(0 ? (T1)0 : (T2)0) -#define type_comb3(T1, T2, T3) type_comb2(T1, type_comb2(T2, T3)) - -#define maybe_int_ptr type_if(int, sizeof(int) == sizeof(llong)) -#define maybe_uint_ptr type_if(unsigned int, sizeof(unsigned int) == sizeof(ullong)) -#define maybe_long_ptr type_if(long, sizeof(long) == sizeof(llong) && sizeof(long) > sizeof(int)) -#define maybe_ulong_ptr type_if(unsigned long, sizeof(unsigned long) == sizeof(ullong) && sizeof(unsigned long) > sizeof(unsigned int)) -#define maybe_long_long_ptr type_if(llong, sizeof(llong) > sizeof(long)) -#define maybe_ulong_long_ptr type_if(ullong, sizeof(ullong) > sizeof(unsigned long)) - -#define intmax_type_ptr type_comb3(maybe_int_ptr, maybe_long_ptr, maybe_long_long_ptr) -#define uintmax_type_ptr type_comb3(maybe_uint_ptr, maybe_ulong_ptr, maybe_ulong_long_ptr) - -typedef __typeof__(*((intmax_type_ptr)0)) intmax_t; -typedef __typeof__(*((uintmax_type_ptr)0)) uintmax_t; +__extension__ typedef __INTMAX_TYPE__ intmax_t; +__extension__ typedef __UINTMAX_TYPE__ uintmax_t; #if __STDC_VERSION__ < 199901L #define restrict /* "restrict" not in old C standard. */ diff --git a/gcc/testsuite/gcc.dg/intmax_t-1.c b/gcc/testsuite/gcc.dg/intmax_t-1.c new file mode 100644 index 00000000000..799d00cfdbc --- /dev/null +++ b/gcc/testsuite/gcc.dg/intmax_t-1.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +/* Compile with -Wall to get a warning if built-in and system intmax_t don't + match. */ + +#include + +__INTMAX_TYPE__ __im_t__; +__UINTMAX_TYPE__ __uim_t__; +intmax_t *im_t_p; +uintmax_t *uim_t_p; + +void +imt (void) +{ + im_t_p = &__im_t__; +} + +void +uimt (void) +{ + uim_t_p = &__uim_t__; +} diff --git a/gcc/testsuite/gcc.dg/torture/builtin-attr-1.c b/gcc/testsuite/gcc.dg/torture/builtin-attr-1.c index 62070c4e71c..21830214edb 100644 --- a/gcc/testsuite/gcc.dg/torture/builtin-attr-1.c +++ b/gcc/testsuite/gcc.dg/torture/builtin-attr-1.c @@ -404,16 +404,7 @@ CPTEST1 (csqrt) CPTEST1 (ctan) CPTEST1 (ctanh) -/* These next definitions are kludges. When GCC has a it - should be used. -*/ -#if __INT_MAX__ == __LONG_LONG_MAX__ -typedef int intmax_t; -#elif __LONG_MAX__ == __LONG_LONG_MAX__ -typedef long intmax_t; -#else -typedef long long intmax_t; -#endif +typedef __INTMAX_TYPE__ intmax_t; /* Various other const builtins. */ TEST1 (abs, int, int)