------- Additional Comments From joseph at codesourcery dot com 2005-06-09 19:29 ------- Subject: Re: GCC should combine adjacent stdio calls
On Thu, 9 Jun 2005, dnovillo at redhat dot com wrote: > Oh, absolutely. The algorithm I'm using will naturally do this. > This is a purely local transformation, we obviously cannot merge > builtins in different control flow paths, so the transformation > goes like this: when we get to a builtin, we try to merge it with > a previously found builtin. The only time we reset the concept > of "previously found builtin" is when we find a CALL_EXPR or an > ASM_EXPR which are the only ones that may have side-effects > affecting the output of the program. > > If the program manipulates the same FILE * that is being used by > the stdio calls, then we'd lose. But I think that's fair game, > right? Although it may not be valid to manipulate the FILE * directly, it seems quite possible that a program might call another <stdio.h> function between the printf calls, that function on the particular implementation having a macro expansion without a function call. It is also possible that values of arguments to the second built-in printf call may depend on the first one having been previously evaluated; for example, given extern char *s; extern int i; printf("%d", i); printf("%.5s", s); you can't merge the printf calls because the first one could have changed what is pointed to by s. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21982