This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Revisiting the TYPE_IS_SIZETYPE issue
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 26 May 2008 10:47:59 +0200
- Subject: Revisiting the TYPE_IS_SIZETYPE issue
Hi,
I think now would be a good time to settle the TYPE_IS_SIZETYPE controversy
and come up with a reasonably well documented semantics for this flag.
To recap, the flag is currently documented in tree.h like so:
/* In an INTEGER_TYPE, it means the type represents a size. We use
this both for validity checking and to permit optimizations that
are unsafe for other types. Note that the C `size_t' type should
*not* have this flag set. The `size_t' type is simply a typedef
for an ordinary integer type that happens to be the type of an
expression returned by `sizeof'; `size_t' has no special
properties. Expressions whose type have TYPE_IS_SIZETYPE set are
always actual sizes. */
#define TYPE_IS_SIZETYPE(NODE) \
The most important part (at least for the Ada compiler) is "to permit
optimizations that are unsafe for other types" and, among them, to permit
bypassing overflow issues for this type by considering that overflow will
never happen for it. That's mentioned in the C front-end too:
/* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where the
second parameter indicates which OPERATOR is being applied. The COMPLAIN
flag controls whether we should diagnose possibly ill-formed
constructs or not. */
tree
c_sizeof_or_alignof_type (tree type, bool is_sizeof, int complain)
[...]
/* VALUE will have an integer type with TYPE_IS_SIZETYPE set.
TYPE_IS_SIZETYPE means that certain things (like overflow) will
never happen. However, this node should really have type
`size_t', which is just a typedef for an ordinary integer type. */
value = fold_convert (size_type_node, value);
gcc_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)));
The issue was raised by the fix for PR middle-end/30364 which has disabled
certain forms of reassociation for signed types on the grounds that they can
introduce undefined overflow:
http://gcc.gnu.org/ml/gcc-patches/2007-09/msg01376.html
But we want to reassociate for TYPE_IS_SIZETYPE because variable-sized types
in Ada generate a lot of size calculations and we want to simplify them at
compile time as much as possible.
An interesting proposition (in my opinion) was to wrap up the flag in a new
macro, e.g. TYPE_OVERFLOW_IGNORED, and use it alongside TYPE_OVERFLOW_WRAPS,
TYPE_OVERFLOW_TRAPS and TYPE_OVERFLOW_UNDEFINED.
Thoughts?
--
Eric Botcazou