Commit 024a85ae by Andreas Krebbel Committed by Andreas Krebbel

c-cppbuiltin.c (builtin_define_type_sizeof): New function.

2007-01-24  Andreas Krebbel  <krebbel1@de.ibm.com>

	* c-cppbuiltin.c (builtin_define_type_sizeof): New function.
	(c_cpp_builtins): New builtin macros: __SIZEOF_INT__, __SIZEOF_LONG__,
	__SIZEOF_LONG_LONG__, __SIZEOF_SHORT__, __SIZEOF_POINTER__,
	__SIZEOF_FLOAT__, __SIZEOF_DOUBLE__, __SIZEOF_LONG_DOUBLE__,
	__SIZEOF_SIZE_T__, __SIZEOF_WCHAR_T__, __SIZEOF_WINT_T__ and
	__SIZEOF_PTRDIFF_T__.
	* doc/cpp.texi: Documentation for the new builtin macros added.

2007-01-24  Andreas Krebbel  <krebbel1@de.ibm.com>

	* gcc.c-torture/compile/sizeof-macros-1.c: New testcase.

From-SVN: r121107
parent 9db27449
2007-01-24 Andreas Krebbel <krebbel1@de.ibm.com>
* c-cppbuiltin.c (builtin_define_type_sizeof): New function.
(c_cpp_builtins): New builtin macros: __SIZEOF_INT__, __SIZEOF_LONG__,
__SIZEOF_LONG_LONG__, __SIZEOF_SHORT__, __SIZEOF_POINTER__,
__SIZEOF_FLOAT__, __SIZEOF_DOUBLE__, __SIZEOF_LONG_DOUBLE__,
__SIZEOF_SIZE_T__, __SIZEOF_WCHAR_T__, __SIZEOF_WINT_T__ and
__SIZEOF_PTRDIFF_T__.
* doc/cpp.texi: Documentation for the new builtin macros added.
2007-01-24 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.md (tanxf2, tan<mode>2, atan<mode>2, log<mode>2,
......
......@@ -58,6 +58,7 @@ static void builtin_define_with_hex_fp_value (const char *, tree,
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_type_sizeof (const char *, tree);
static void builtin_define_float_constants (const char *,
const char *,
const char *,
......@@ -71,6 +72,14 @@ builtin_define_type_precision (const char *name, tree type)
builtin_define_with_int_value (name, TYPE_PRECISION (type));
}
/* Define NAME with value TYPE size_unit. */
static void
builtin_define_type_sizeof (const char *name, tree type)
{
builtin_define_with_int_value (name,
tree_low_cst (TYPE_SIZE_UNIT (type), 1));
}
/* Define the float.h constants for TYPE using NAME_PREFIX, FP_SUFFIX,
and FP_CAST. */
static void
......@@ -549,6 +558,24 @@ c_cpp_builtins (cpp_reader *pfile)
if (flag_openmp)
cpp_define (pfile, "_OPENMP=200505");
builtin_define_type_sizeof ("__SIZEOF_INT__", integer_type_node);
builtin_define_type_sizeof ("__SIZEOF_LONG__", long_integer_type_node);
builtin_define_type_sizeof ("__SIZEOF_LONG_LONG__",
long_long_integer_type_node);
builtin_define_type_sizeof ("__SIZEOF_SHORT__", short_integer_type_node);
builtin_define_type_sizeof ("__SIZEOF_FLOAT__", float_type_node);
builtin_define_type_sizeof ("__SIZEOF_DOUBLE__", double_type_node);
builtin_define_type_sizeof ("__SIZEOF_LONG_DOUBLE__", long_double_type_node);
builtin_define_type_sizeof ("__SIZEOF_SIZE_T__", size_type_node);
builtin_define_type_sizeof ("__SIZEOF_WCHAR_T__", wchar_type_node);
builtin_define_type_sizeof ("__SIZEOF_WINT_T__", wint_type_node);
builtin_define_type_sizeof ("__SIZEOF_PTRDIFF_T__",
unsigned_ptrdiff_type_node);
/* ptr_type_node can't be used here since ptr_mode is only set when
toplev calls backend_init which is not done with -E switch. */
builtin_define_with_int_value ("__SIZEOF_POINTER__",
POINTER_SIZE / BITS_PER_UNIT);
/* A straightforward target hook doesn't work, because of problems
linking that hook's body when part of non-C front ends. */
# define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
......
......@@ -2079,6 +2079,23 @@ 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.
@item __SIZEOF_INT__
@itemx __SIZEOF_LONG__
@itemx __SIZEOF_LONG_LONG__
@itemx __SIZEOF_SHORT__
@itemx __SIZEOF_POINTER__
@itemx __SIZEOF_FLOAT__
@itemx __SIZEOF_DOUBLE__
@itemx __SIZEOF_LONG_DOUBLE__
@itemx __SIZEOF_SIZE_T__
@itemx __SIZEOF_WCHAR_T__
@itemx __SIZEOF_WINT_T__
@itemx __SIZEOF_PTRDIFF_T__
Defined to the number of bytes of the C standard data types: @code{int},
@code{long}, @code{long long}, @code{short}, @code{void *}, @code{float},
@code{double}, @code{long double}, @code{size_t}, @code{wchar_t}, @code{wint_t}
and @code{ptrdiff_t}.
@item __DEPRECATED
This macro is defined, with value 1, when compiling a C++ source file
with warnings about deprecated constructs enabled. These warnings are
......
2007-01-24 Andreas Krebbel <krebbel1@de.ibm.com>
* gcc.c-torture/compile/sizeof-macros-1.c: New testcase.
2007-01-23 Andrew Pinski <pinskia@gmail.com>
PR objc/27438
/* This checks the gcc builtin macros defined to the byte
sizes of C standard types. */
int a[sizeof(int) == __SIZEOF_INT__ ? 1 : -1];
int b[sizeof(long) == __SIZEOF_LONG__ ? 1 : -1];
int c[sizeof(long long) == __SIZEOF_LONG_LONG__ ? 1 : -1];
int d[sizeof(short) == __SIZEOF_SHORT__ ? 1 : -1];
int e[sizeof(void *) == __SIZEOF_POINTER__ ? 1 : -1];
int f[sizeof(float) == __SIZEOF_FLOAT__ ? 1 : -1];
int g[sizeof(double) == __SIZEOF_DOUBLE__ ? 1 : -1];
int h[sizeof(long double) == __SIZEOF_LONG_DOUBLE__ ? 1 : -1];
int i[sizeof(__SIZE_TYPE__) == __SIZEOF_SIZE_T__ ? 1 : -1];
int j[sizeof(__WCHAR_TYPE__) == __SIZEOF_WCHAR_T__ ? 1 : -1];
int k[sizeof(__WINT_TYPE__) == __SIZEOF_WINT_T__ ? 1 : -1];
int l[sizeof(__PTRDIFF_TYPE__) == __SIZEOF_PTRDIFF_T__ ? 1 : -1];
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