[PATCH] improve C++ code by changing fold-const.c
Roger Sayle
roger@eyesopen.com
Fri May 21 19:19:00 GMT 2004
On Fri, 21 May 2004, Andrew Pinski wrote:
> Here is a C example of where this can happen
> #include <stdio.h>
>
> static char* funk() {
> return "Hello World.\n";
> }
>
> static void funky(char*(*func)()) {
> printf("%s", func());
> }
>
> void main() {
> funky(funk);
> }
>
> Note that before this patch there is a cast in there which causes the
> function call to be outputted as an indirect call at first and then
> converted by combine to be an direct call (because of your 2004-03-12
> patch). Now with my patch the call to funk is converted into direct
> call as there is no cast in there.
Is this a platform specific problem or could it have been fixed recently?
On i686-pc-linux-gnu, both the C and C++ versions of your example program
contain a direct call to funk (or _Z4funkv) in .01.rtl using mainline
CVS. This is clearly long before we reach combine.
.t10.gimple contains:
char * (*<T263>) () func;
func = (char * (*<T263>) ())funk;
{
char * T.0;
T.0 = func ();
printf ("%s", T.0);
}
by .t13.lower we have:
func = funk;
T.0 = func ();
printf ("%s", T.0);
and then by .t23.dce2 we have:
T.0_2 = funk ();
printf ("%s", T.0_2);
Perhaps, there's a better example to demonstrate this issue?
Or perhaps I'm still misunderstanding the problem?
Roger
--
More information about the Gcc-patches
mailing list