This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Promotion of integer return types to int
- From: Alexandre Courbot <Alexandre dot Courbot at lifl dot fr>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 19 Sep 2003 16:21:19 +0200
- Subject: Promotion of integer return types to int
Hello everybody,
I couldn't help but notice that the C parser automatically promotes any type
that can be promoted to int when used to return values. This happens in
c-decl.c, line 5650:
/* Promote the value to int before returning it. */
if (c_promoting_integer_type_p (restype))
{
/* It retains unsignedness if not really getting wider. */
if (TREE_UNSIGNED (restype)
&& (TYPE_PRECISION (restype)
== TYPE_PRECISION (integer_type_node)))
restype = unsigned_type_node;
else
restype = integer_type_node;
}
c_promoting_integer_type_p always returns 1 when given a char or short type.
As a consequence, the integer promotion is made at tree level and if I
compile the following function:
unsigned char function_returns_char();
Then I have no way to know that the return type is char-sized. My backend is
fooled and believes it is int-sized. This is a serious issue for me because I
have to specify the return type of the functions in the assembler file and
all the functions returning chars or shorts actually return ints.
Since I'm porting to an target for embedded devices (typically smartcards),
this is a real issue and I wondered if the promotion couldn't be optional.
I've noticed that someone already submitted a patch for this
(http://gcc.gnu.org/ml/gcc-patches/2003-05/msg01630.html) but it hasn't been
included. For my use I really need the return types not to be promoted, so
I'll disable it, but I guess it could be useful to others if this feature was
added. Maybe a new, dedicated macro? If not defined, the promotion would
happen just as it does today. If no one bothers, shall I go ahead and submit
a patch?
Thanks,
Alex.