[PATCH] Optimize sprintf into strcpy if possible

Jakub Jelinek jakub@redhat.com
Sat Apr 7 00:25:00 GMT 2001


On Fri, Apr 06, 2001 at 04:43:15PM -0400, Kaveh R. Ghazi wrote:
>  > This patch optimizes sprintf (x, "%s", y) into strcpy (x, y) and also
>  > sprintf (x, "foowithoutpercentcharacter") into strcpy (x, "foo....").
> 
> 
> One reason I didn't write this one when I initially did the stdio opts
> was that I worried what happens when e.g. on older hosts sprintf is
> declared in stdio.h to return char* ?
> 
> I think sunos4 is one such host, can you please test it there to make
> sure it at least degrades gracefully (or perhaps make it actually
> work?)

I don't have access to SunOS at all, is the prototype
char *sprintf();
there?
For the sprintf optimization, we don't really care about return value (only
optimize if it is not used, since strcpy has different result than sprintf),
so I think the easiest way would be to teach duplicate_decls that if certain
tree node is used for return value, it should just silently override the
builtin with the new prototype.
> 
> Minor addition request:
> You could probably add optimizing sprintf(x, "%c", c) into *x=(char)c;
> using INDIRECT_REF, MODIFY_EXPR and CONVERT_EXPR to create the proper
> tree expression.

Yeah, I thought about it too, was just too lazy to code it up yesterday.

	Jakub



More information about the Gcc-patches mailing list