diff options
author | Andreas Krebbel <krebbel1@de.ibm.com> | 2007-01-24 12:03:38 +0000 |
---|---|---|
committer | Andreas Krebbel <krebbel@gcc.gnu.org> | 2007-01-24 12:03:38 +0000 |
commit | 024a85aeb6a912811d917f737eaad39140c2fb0c (patch) | |
tree | 06f74328e5fa1bec8c013b5ce2683658b5237193 /gcc/c-cppbuiltin.c | |
parent | 9db27449884f6c83ff2862450620ca979b541427 (diff) | |
download | gcc-024a85aeb6a912811d917f737eaad39140c2fb0c.zip gcc-024a85aeb6a912811d917f737eaad39140c2fb0c.tar.gz gcc-024a85aeb6a912811d917f737eaad39140c2fb0c.tar.bz2 |
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
Diffstat (limited to 'gcc/c-cppbuiltin.c')
-rw-r--r-- | gcc/c-cppbuiltin.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/c-cppbuiltin.c b/gcc/c-cppbuiltin.c index 4eca2d4..729cb0b 100644 --- a/gcc/c-cppbuiltin.c +++ b/gcc/c-cppbuiltin.c @@ -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) |