This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC,PATCH] Builtin macros for sizes of standard types
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Andreas Krebbel <Andreas dot Krebbel at de dot ibm dot com>
- Cc: gcc-patches at gcc dot gnu dot org, joseph at codesourcery dot com
- Date: Tue, 23 Jan 2007 09:23:20 -0800
- Subject: Re: [RFC,PATCH] Builtin macros for sizes of standard types
- References: <20070123133300.GA3297@blc4eb430604175.ibm.com>
Andreas Krebbel wrote:
> 2007-01-23 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_SIZE_T__, __SIZEOF_FLOAT__, __SIZEOF_DOUBLE__ and
> __SIZEOF_LONG_DOUBLE__.
> * doc/cpp.texi: Documentation for the new builtin macros added.
>
> 2007-01-23 Andreas Krebbel <krebbel1@de.ibm.com>
>
> * gcc.c-torture/compile/sizeof-macros-1.c: New testcase.
This version is almost OK.
> + /* 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_INT_CST_LOW (TYPE_SIZE_UNIT (type)));
> + }
This should int_cst_low, rather than TREE_INT_CST_LOW. TREE_INT_CST_LOW
should be used only in very special circumstances; using int_cst_low is
the safe interface. You should pass "1" for the "unsignedp" argument,
since sizes are unsigned.
OK with that change.
(I don't like the fact that GCC plays so fast and loose with
signed/unsigned quantities. For example, we really shoud have a
unsigned_int_cst_low, which returns an unsigned HOST_WIDE_INT, and then
we should call builtin_define_with_uint_value here. I know that we're
unlikely to have a builtin type with a size that would appear negative
if considered as a signed quantity, but still, this is just sloppy
design. It's not your fault, though; I'm just griping.)
Thanks,
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713