This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
casting return values
- From: Dan Nicolaescu <dann at godzilla dot ics dot uci dot edu>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 13 May 2004 19:43:46 -0700
- Subject: casting return values
Currently return values for C/C++ functions that return types for
which c_promoting_integer_type_p is true are cast to integer
(see c-decl.c:start_function and cp/decl.c:start_function)
The effect of this can be seen when compiling:
static _Bool bar (_Bool a)
{
return a;
}
_Bool foo1 (_Bool a)
{
if (bar(a))
return 1;
else
return 0;
}
The -fdump-tree-generic dump looks like:
;; Function bar (bar)
bar (a)
{
return (int)a; /* see the cast here! */
}
foo1 (a)
{
int T.11;
_Bool T.12;
int T.13;
T.11 = (int)a; /* this is probably not needed either */
T.12 = bar (T.11);
T.13 = (int)T.12;
if (T.13 != 0)
{
return 1;
}
else
{
return 0;
}
}
And the .vars dump like:
foo1 (a)
{
<bb 0>:
/*Note the useless casts and comparisons. */
if ((_Bool)(int)((int)a != 0) != 0) goto <L1>; else goto <L2>;
<L1>:;
return 1;
<L2>:;
return 0;
}
These casts are also the cause of PR14441.
The casts introduced by start_functions are required by the ABI. But
start_functions is too early to introduce such casts in the tree-ssa
world. They are probably not needed before generating RTL.
The following patch, although it bootstraps with no regressions on
x86-linux and sparc-solaris is probably technically incorrect.
Where should the deleted code be placed? As a langhook called in
expand_return? Please advice.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.334.2.94
diff -c -3 -p -c -r1.334.2.94 c-decl.c
*** c-decl.c 12 May 2004 13:33:28 -0000 1.334.2.94
--- c-decl.c 14 May 2004 02:38:48 -0000
*************** start_function (tree declspecs, tree dec
*** 5791,5807 ****
make_decl_rtl (current_function_decl, NULL);
restype = TREE_TYPE (TREE_TYPE (current_function_decl));
- /* Promote the value to int before returning it. */
- if (c_promoting_integer_type_p (restype))
- {
- /* It retains unsignedness if not really getting wider. */
- if (TYPE_UNSIGNED (restype)
- && (TYPE_PRECISION (restype)
- == TYPE_PRECISION (integer_type_node)))
- restype = unsigned_type_node;
- else
- restype = integer_type_node;
- }
DECL_RESULT (current_function_decl)
= build_decl (RESULT_DECL, NULL_TREE, restype);
--- 5791,5796 ----
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.911.2.72
diff -c -3 -p -c -r1.911.2.72 decl.c
*** decl.c 12 May 2004 13:34:47 -0000 1.911.2.72
--- decl.c 14 May 2004 02:39:34 -0000
*************** start_function (tree declspecs, tree dec
*** 10148,10156 ****
/* Build the return declaration for the function. */
restype = TREE_TYPE (fntype);
- /* Promote the value to int before returning it. */
- if (c_promoting_integer_type_p (restype))
- restype = type_promotes_to (restype);
if (DECL_RESULT (decl1) == NULL_TREE)
{
DECL_RESULT (decl1)
--- 10148,10153 ----
The patch reduces the GC memory consumption for PR8361 by about 1%.
Thanks.
--dan