Commit b15ad712 by Joseph Myers Committed by Joseph Myers

tm.texi (INTMAX_TYPE, [...]): Define.

	* tm.texi (INTMAX_TYPE, UINTMAX_TYPE): Define.
	* c-common.h (enum c_tree_index): Add CTI_INTMAX_TYPE and
	CTI_UINTMAX_TYPE.
	(intmax_type_node, uintmax_type_node): Define.
	* c-common.c (decl_attributes): If pedantic, warn if `mode'
	attributes create a type wider than intmax_t.
	(T_IM, T_UIM): Define properly.
	* c-decl.c (INTMAX_TYPE, UINTMAX_TYPE): Define if not already
	defined.
	(init_decl_processing): Initialize intmax_type_node and
	uintmax_type_node.
	* c-lex.c (lex_number): When pedantic and warning for integer
	constants that are too large, in C99 mode warn for those that have
	a type wider than long long.

cp:
	* decl.c (INTMAX_TYPE, UINTMAX_TYPE): Define if not already
	defined.
	(init_decl_processing): Initialize intmax_type_node and
	uintmax_type_node.

testsuite:
	* gcc.dg/c99-printf-1.c, gcc.dg/c99-scanf-1.c,
	gcc.dg/c90-printf-2.c, gcc.dg/c90-scanf-2.c: Define intmax_t and
	uintmax_t using <limits.h> to emulate the compiler's internal
	logic.  No longer XFAIL %j tests.

From-SVN: r36791
parent 2588e44e
2000-10-08 Joseph S. Myers <jsm28@cam.ac.uk> 2000-10-08 Joseph S. Myers <jsm28@cam.ac.uk>
* tm.texi (INTMAX_TYPE, UINTMAX_TYPE): Define.
* c-common.h (enum c_tree_index): Add CTI_INTMAX_TYPE and
CTI_UINTMAX_TYPE.
(intmax_type_node, uintmax_type_node): Define.
* c-common.c (decl_attributes): If pedantic, warn if `mode'
attributes create a type wider than intmax_t.
(T_IM, T_UIM): Define properly.
* c-decl.c (INTMAX_TYPE, UINTMAX_TYPE): Define if not already
defined.
(init_decl_processing): Initialize intmax_type_node and
uintmax_type_node.
* c-lex.c (lex_number): When pedantic and warning for integer
constants that are too large, in C99 mode warn for those that have
a type wider than long long.
2000-10-08 Joseph S. Myers <jsm28@cam.ac.uk>
* c-common.c (FMT_FLAG_ARG_CONVERT, FMT_FLAG_SCANF_A_KLUDGE, * c-common.c (FMT_FLAG_ARG_CONVERT, FMT_FLAG_SCANF_A_KLUDGE,
FMT_FLAG_FANCY_PERCENT_OK): Define. FMT_FLAG_FANCY_PERCENT_OK): Define.
(format_char_info): Add flag "4" to comment. (format_char_info): Add flag "4" to comment.
......
...@@ -761,6 +761,12 @@ decl_attributes (node, attributes, prefix_attributes) ...@@ -761,6 +761,12 @@ decl_attributes (node, attributes, prefix_attributes)
error ("no data type for mode `%s'", p); error ("no data type for mode `%s'", p);
else else
{ {
if (TYPE_PRECISION (typefm) > (TREE_UNSIGNED (type)
? TYPE_PRECISION(uintmax_type_node)
: TYPE_PRECISION(intmax_type_node))
&& pedantic)
pedwarn ("type with more precision than %s",
TREE_UNSIGNED (type) ? "uintmax_t" : "intmax_t");
TREE_TYPE (decl) = type = typefm; TREE_TYPE (decl) = type = typefm;
DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0; DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
layout_decl (decl, 0); layout_decl (decl, 0);
...@@ -1589,9 +1595,9 @@ static const format_flag_pair strftime_flag_pairs[] = ...@@ -1589,9 +1595,9 @@ static const format_flag_pair strftime_flag_pairs[] =
#define T99_PD { STD_C99, "ptrdiff_t", T_PD } #define T99_PD { STD_C99, "ptrdiff_t", T_PD }
#define T_UPD &unsigned_ptrdiff_type_node #define T_UPD &unsigned_ptrdiff_type_node
#define T99_UPD { STD_C99, "unsigned ptrdiff_t", T_UPD } #define T99_UPD { STD_C99, "unsigned ptrdiff_t", T_UPD }
#define T_IM NULL /* intmax_t not yet implemented. */ #define T_IM &intmax_type_node
#define T99_IM { STD_C99, "intmax_t", T_IM } #define T99_IM { STD_C99, "intmax_t", T_IM }
#define T_UIM NULL /* uintmax_t not yet implemented. */ #define T_UIM &uintmax_type_node
#define T99_UIM { STD_C99, "uintmax_t", T_UIM } #define T99_UIM { STD_C99, "uintmax_t", T_UIM }
static const format_char_info print_char_table[] = static const format_char_info print_char_table[] =
......
...@@ -119,6 +119,8 @@ enum c_tree_index ...@@ -119,6 +119,8 @@ enum c_tree_index
CTI_C_SIZE_TYPE, /* For format checking only. */ CTI_C_SIZE_TYPE, /* For format checking only. */
CTI_SIGNED_SIZE_TYPE, /* For format checking only. */ CTI_SIGNED_SIZE_TYPE, /* For format checking only. */
CTI_UNSIGNED_PTRDIFF_TYPE, /* For format checking only. */ CTI_UNSIGNED_PTRDIFF_TYPE, /* For format checking only. */
CTI_INTMAX_TYPE,
CTI_UINTMAX_TYPE,
CTI_WIDEST_INT_LIT_TYPE, CTI_WIDEST_INT_LIT_TYPE,
CTI_WIDEST_UINT_LIT_TYPE, CTI_WIDEST_UINT_LIT_TYPE,
...@@ -161,6 +163,8 @@ enum c_tree_index ...@@ -161,6 +163,8 @@ enum c_tree_index
#define c_size_type_node c_global_trees[CTI_C_SIZE_TYPE] #define c_size_type_node c_global_trees[CTI_C_SIZE_TYPE]
#define signed_size_type_node c_global_trees[CTI_SIGNED_SIZE_TYPE] #define signed_size_type_node c_global_trees[CTI_SIGNED_SIZE_TYPE]
#define unsigned_ptrdiff_type_node c_global_trees[CTI_UNSIGNED_PTRDIFF_TYPE] #define unsigned_ptrdiff_type_node c_global_trees[CTI_UNSIGNED_PTRDIFF_TYPE]
#define intmax_type_node c_global_trees[CTI_INTMAX_TYPE]
#define uintmax_type_node c_global_trees[CTI_UINTMAX_TYPE]
#define widest_integer_literal_type_node c_global_trees[CTI_WIDEST_INT_LIT_TYPE] #define widest_integer_literal_type_node c_global_trees[CTI_WIDEST_INT_LIT_TYPE]
#define widest_unsigned_literal_type_node c_global_trees[CTI_WIDEST_UINT_LIT_TYPE] #define widest_unsigned_literal_type_node c_global_trees[CTI_WIDEST_UINT_LIT_TYPE]
......
...@@ -77,6 +77,22 @@ enum decl_context ...@@ -77,6 +77,22 @@ enum decl_context
#ifndef WINT_TYPE #ifndef WINT_TYPE
#define WINT_TYPE "unsigned int" #define WINT_TYPE "unsigned int"
#endif #endif
#ifndef INTMAX_TYPE
#define INTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
? "int" \
: ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
? "long int" \
: "long long int"))
#endif
#ifndef UINTMAX_TYPE
#define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
? "unsigned int" \
: ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
? "long unsigned int" \
: "long long unsigned int"))
#endif
/* Do GC. */ /* Do GC. */
int ggc_p = 1; int ggc_p = 1;
...@@ -3078,6 +3094,11 @@ init_decl_processing () ...@@ -3078,6 +3094,11 @@ init_decl_processing ()
wint_type_node = wint_type_node =
TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WINT_TYPE))); TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WINT_TYPE)));
intmax_type_node =
TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (INTMAX_TYPE)));
uintmax_type_node =
TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (UINTMAX_TYPE)));
boolean_type_node = integer_type_node; boolean_type_node = integer_type_node;
boolean_true_node = integer_one_node; boolean_true_node = integer_one_node;
boolean_false_node = integer_zero_node; boolean_false_node = integer_zero_node;
......
...@@ -2287,11 +2287,19 @@ lex_number (str, len) ...@@ -2287,11 +2287,19 @@ lex_number (str, len)
warning ("width of integer constant may change on other systems with -traditional"); warning ("width of integer constant may change on other systems with -traditional");
} }
if (pedantic && !flag_traditional && !spec_long_long && !warn if (pedantic && !flag_traditional && (flag_isoc99 || !spec_long_long)
&& (TYPE_PRECISION (long_integer_type_node) < TYPE_PRECISION (type))) && !warn
&& ((flag_isoc99
? TYPE_PRECISION (long_long_integer_type_node)
: TYPE_PRECISION (long_integer_type_node)) < TYPE_PRECISION (type)))
{ {
warn = 1; warn = 1;
pedwarn ("integer constant larger than the maximum value of an unsigned long int"); pedwarn ("integer constant larger than the maximum value of %s",
(flag_isoc99
? (TREE_UNSIGNED (type)
? "an unsigned long long int"
: "a long long int")
: "an unsigned long int"));
} }
if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type)) if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
......
2000-10-08 Joseph S. Myers <jsm28@cam.ac.uk>
* decl.c (INTMAX_TYPE, UINTMAX_TYPE): Define if not already
defined.
(init_decl_processing): Initialize intmax_type_node and
uintmax_type_node.
2000-10-06 Richard Henderson <rth@cygnus.com> 2000-10-06 Richard Henderson <rth@cygnus.com>
* cp-tree.h (struct cp_language_function): Remove x_result_rtx. * cp-tree.h (struct cp_language_function): Remove x_result_rtx.
......
...@@ -83,6 +83,22 @@ int ggc_p = 1; ...@@ -83,6 +83,22 @@ int ggc_p = 1;
#define WCHAR_TYPE "int" #define WCHAR_TYPE "int"
#endif #endif
#ifndef INTMAX_TYPE
#define INTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
? "int" \
: ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
? "long int" \
: "long long int"))
#endif
#ifndef UINTMAX_TYPE
#define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
? "unsigned int" \
: ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
? "long unsigned int" \
: "long long unsigned int"))
#endif
static tree grokparms PARAMS ((tree, int)); static tree grokparms PARAMS ((tree, int));
static const char *redeclaration_error_message PARAMS ((tree, tree)); static const char *redeclaration_error_message PARAMS ((tree, tree));
...@@ -6542,6 +6558,11 @@ init_decl_processing () ...@@ -6542,6 +6558,11 @@ init_decl_processing ()
wchar_array_type_node wchar_array_type_node
= build_array_type (wchar_type_node, array_domain_type); = build_array_type (wchar_type_node, array_domain_type);
intmax_type_node =
TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (INTMAX_TYPE)));
uintmax_type_node =
TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (UINTMAX_TYPE)));
if (flag_vtable_thunks) if (flag_vtable_thunks)
{ {
/* Make sure we get a unique function type, so we can give /* Make sure we get a unique function type, so we can give
......
2000-10-08 Joseph S. Myers <jsm28@cam.ac.uk> 2000-10-08 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/c99-printf-1.c, gcc.dg/c99-scanf-1.c,
gcc.dg/c90-printf-2.c, gcc.dg/c90-scanf-2.c: Define intmax_t and
uintmax_t using <limits.h> to emulate the compiler's internal
logic. No longer XFAIL %j tests.
2000-10-08 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/c90-printf-1.c, gcc.dg/c90-scanf-1.c, * gcc.dg/c90-printf-1.c, gcc.dg/c90-scanf-1.c,
gcc.dg/c99-printf-1.c, gcc.dg/c99-scanf-1.c, gcc.dg/c99-printf-1.c, gcc.dg/c99-scanf-1.c,
gcc.dg/c99-strftime-1.c, gcc.dg/format-ext-3.c: Adjust error gcc.dg/c99-strftime-1.c, gcc.dg/format-ext-3.c: Adjust error
......
...@@ -10,12 +10,17 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; ...@@ -10,12 +10,17 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
__extension__ typedef long long int llong; __extension__ typedef long long int llong;
/* This next definition is broken. When GCC has a <stdint.h> and /* This next definition is a kludge. When GCC has a <stdint.h> it
an internal understanding of intmax_t, it should be should be used.
replaced by an include of <stdint.h> or by a definition for internal
macros or typedefs.
*/ */
__extension__ typedef long long int intmax_t; #include <limits.h>
#if INT_MAX == LLONG_MAX
typedef int intmax_t;
#elif LONG_MAX == LLONG_MAX
typedef long intmax_t;
#else
__extension__ typedef long long intmax_t;
#endif
extern int printf (const char *, ...); extern int printf (const char *, ...);
......
...@@ -10,12 +10,17 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; ...@@ -10,12 +10,17 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
__extension__ typedef long long int llong; __extension__ typedef long long int llong;
/* This next definition is broken. When GCC has a <stdint.h> and /* This next definition is a kludge. When GCC has a <stdint.h> it
an internal understanding of intmax_t, it should be should be used.
replaced by an include of <stdint.h> or by a definition for internal
macros or typedefs.
*/ */
__extension__ typedef long long int intmax_t; #include <limits.h>
#if INT_MAX == LLONG_MAX
typedef int intmax_t;
#elif LONG_MAX == LLONG_MAX
typedef long intmax_t;
#else
__extension__ typedef long long intmax_t;
#endif
extern int scanf (const char *, ...); extern int scanf (const char *, ...);
......
...@@ -16,13 +16,24 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; ...@@ -16,13 +16,24 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __SIZE_TYPE__ signed_size_t; typedef __SIZE_TYPE__ signed_size_t;
#undef unsigned #undef unsigned
/* These next definitions are broken. When GCC has a <stdint.h> and /* These next definitions are kludges. When GCC has a <stdint.h> it
an internal understanding of intmax_t and uintmax_t, they should be should be used.
replaced by an include of <stdint.h> or by definitions for internal
macros or typedefs, and the corresponding xfails removed.
*/ */
typedef long long int intmax_t; #include <limits.h>
typedef unsigned long long int uintmax_t; #if INT_MAX == LLONG_MAX
typedef int intmax_t;
#elif LONG_MAX == LLONG_MAX
typedef long intmax_t;
#else
typedef long long intmax_t;
#endif
#if UINT_MAX == ULLONG_MAX
typedef unsigned int uintmax_t;
#elif ULONG_MAX == ULLONG_MAX
typedef unsigned long uintmax_t;
#else
typedef unsigned long long uintmax_t;
#endif
extern int printf (const char *, ...); extern int printf (const char *, ...);
...@@ -82,8 +93,8 @@ foo (int i, unsigned int u, double d, char *s, void *p, int *n, ...@@ -82,8 +93,8 @@ foo (int i, unsigned int u, double d, char *s, void *p, int *n,
printf ("%llc", i); /* { dg-warning "length" "bad use of %ll" } */ printf ("%llc", i); /* { dg-warning "length" "bad use of %ll" } */
printf ("%lls", s); /* { dg-warning "length" "bad use of %ll" } */ printf ("%lls", s); /* { dg-warning "length" "bad use of %ll" } */
printf ("%llp", p); /* { dg-warning "length" "bad use of %ll" } */ printf ("%llp", p); /* { dg-warning "length" "bad use of %ll" } */
printf ("%jd%ji%jo%ju%jx%jX", j, j, uj, uj, uj, uj); /* { dg-bogus "length" "bogus %j warning" { xfail *-*-* } } */ printf ("%jd%ji%jo%ju%jx%jX", j, j, uj, uj, uj, uj); /* { dg-bogus "length" "bogus %j warning" { target *-*-* } } */
printf ("%jn", jn); /* { dg-bogus "length" "bogus %j warning" { xfail *-*-* } } */ printf ("%jn", jn); /* { dg-bogus "length" "bogus %j warning" { target *-*-* } } */
printf ("%jf", d); /* { dg-warning "length" "bad use of %j" } */ printf ("%jf", d); /* { dg-warning "length" "bad use of %j" } */
printf ("%jF", d); /* { dg-warning "length" "bad use of %j" } */ printf ("%jF", d); /* { dg-warning "length" "bad use of %j" } */
printf ("%je", d); /* { dg-warning "length" "bad use of %j" } */ printf ("%je", d); /* { dg-warning "length" "bad use of %j" } */
......
...@@ -18,13 +18,24 @@ typedef __SIZE_TYPE__ signed_size_t; ...@@ -18,13 +18,24 @@ typedef __SIZE_TYPE__ signed_size_t;
typedef unsigned __PTRDIFF_TYPE__ unsigned_ptrdiff_t; typedef unsigned __PTRDIFF_TYPE__ unsigned_ptrdiff_t;
#undef signed #undef signed
/* These next definitions are broken. When GCC has a <stdint.h> and /* These next definitions are kludges. When GCC has a <stdint.h> it
an internal understanding of intmax_t and uintmax_t, they should be should be used.
replaced by an include of <stdint.h> or by definitions for internal
macros or typedefs, and the corresponding xfails removed.
*/ */
typedef long long int intmax_t; #include <limits.h>
typedef unsigned long long int uintmax_t; #if INT_MAX == LLONG_MAX
typedef int intmax_t;
#elif LONG_MAX == LLONG_MAX
typedef long intmax_t;
#else
typedef long long intmax_t;
#endif
#if UINT_MAX == ULLONG_MAX
typedef unsigned int uintmax_t;
#elif ULONG_MAX == ULLONG_MAX
typedef unsigned long uintmax_t;
#else
typedef unsigned long long uintmax_t;
#endif
extern int scanf (const char *, ...); extern int scanf (const char *, ...);
...@@ -102,7 +113,7 @@ foo (int *ip, unsigned int *uip, short int *hp, unsigned short int *uhp, ...@@ -102,7 +113,7 @@ foo (int *ip, unsigned int *uip, short int *hp, unsigned short int *uhp,
scanf ("%ll[ac]", s); /* { dg-warning "length" "bad use of %ll" } */ scanf ("%ll[ac]", s); /* { dg-warning "length" "bad use of %ll" } */
scanf ("%llc", s); /* { dg-warning "length" "bad use of %ll" } */ scanf ("%llc", s); /* { dg-warning "length" "bad use of %ll" } */
scanf ("%llp", pp); /* { dg-warning "length" "bad use of %ll" } */ scanf ("%llp", pp); /* { dg-warning "length" "bad use of %ll" } */
scanf ("%jd%ji%jo%ju%jx%jX%jn", jp, jp, ujp, ujp, ujp, ujp, jn); /* { dg-bogus "length" "bogus %j warning" { xfail *-*-* } } */ scanf ("%jd%ji%jo%ju%jx%jX%jn", jp, jp, ujp, ujp, ujp, ujp, jn); /* { dg-bogus "length" "bogus %j warning" { target *-*-* } } */
scanf ("%ja", fp); /* { dg-warning "length" "bad use of %j" } */ scanf ("%ja", fp); /* { dg-warning "length" "bad use of %j" } */
scanf ("%jA", fp); /* { dg-warning "length" "bad use of %j" } */ scanf ("%jA", fp); /* { dg-warning "length" "bad use of %j" } */
scanf ("%je", fp); /* { dg-warning "length" "bad use of %j" } */ scanf ("%je", fp); /* { dg-warning "length" "bad use of %j" } */
......
...@@ -1331,6 +1331,29 @@ information. ...@@ -1331,6 +1331,29 @@ information.
If you don't define this macro, the default is @code{"unsigned int"}. If you don't define this macro, the default is @code{"unsigned int"}.
@findex INTMAX_TYPE
@item INTMAX_TYPE
A C expression for a string describing the name of the data type that
can represent any value of any standard or extended signed integer type.
The typedef name @code{intmax_t} is defined using the contents of the
string. See @code{SIZE_TYPE} above for more information.
If you don't define this macro, the default is the first of
@code{"int"}, @code{"long int"}, or @code{"long long int"} that has as
much precision as @code{long long int}.
@findex UINTMAX_TYPE
@item UINTMAX_TYPE
A C expression for a string describing the name of the data type that
can represent any value of any standard or extended unsigned integer
type. The typedef name @code{uintmax_t} is defined using the contents
of the string. See @code{SIZE_TYPE} above for more information.
If you don't define this macro, the default is the first of
@code{"unsigned int"}, @code{"long unsigned int"}, or @code{"long long
unsigned int"} that has as much precision as @code{long long unsigned
int}.
@findex OBJC_INT_SELECTORS @findex OBJC_INT_SELECTORS
@item OBJC_INT_SELECTORS @item OBJC_INT_SELECTORS
Define this macro if the type of Objective C selectors should be Define this macro if the type of Objective C selectors should be
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment