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
This commit is contained in:
Joseph Myers 2004-08-05 01:38:31 +01:00 committed by Joseph Myers
parent 5a05b7c5da
commit 852910694f
11 changed files with 80 additions and 77 deletions

View File

@ -1,3 +1,12 @@
2004-08-05 Joseph S. Myers <jsm@polyomino.org.uk>
* 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 <edelsohn@gnu.org>
* config/rs6000/rs6000.c (rs6000_rtx_costs): LABEL_REFs are zero

View File

@ -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

View File

@ -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 <stdint.h>. 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__",

View File

@ -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.

View File

@ -1,3 +1,12 @@
2004-08-05 Joseph S. Myers <jsm@polyomino.org.uk>
* 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 <giovannibajo@gcc.gnu.org>
* g++.dg/tc1/dr147.C: Add reference to PR.

View File

@ -1,20 +1,9 @@
/* Test for builtin abs, labs, llabs, imaxabs. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* These next definitions are kludges. When GCC has a <stdint.h> it
should be used.
*/
#include <limits.h>
#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);

View File

@ -1,20 +1,9 @@
/* Test for builtin abs, labs, llabs, imaxabs. Test for __builtin versions. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* These next definitions are kludges. When GCC has a <stdint.h> it
should be used.
*/
#include <limits.h>
#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);

View File

@ -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 <stdint.h> it
should be used.
*/
#include <limits.h>
#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)

View File

@ -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 <stdint.h> 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. */

View File

@ -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 <inttypes.h>
__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__;
}

View File

@ -404,16 +404,7 @@ CPTEST1 (csqrt)
CPTEST1 (ctan)
CPTEST1 (ctanh)
/* These next definitions are kludges. When GCC has a <stdint.h> 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)