------- Additional Comments From joseph at codesourcery dot com  2005-06-09 
20:13 -------
Subject: Re:  GCC should combine adjacent stdio
 calls

On Thu, 9 Jun 2005, dnovillo at redhat dot com wrote:

> Gah, so we'll need to parse the format string then.  Oh, well.

We'll need to parse the format string anyway to know if there are excess 
arguments to the first printf which should not be printed, and if %n or 
operand numbers appear.

For the other issues, it's the arguments to the second printf and anything 
else evaluated between the two printfs that matter:

If anything evaluated might change the contents of the FILE * or anything 
pointed to therein (e.g. local buffers passed to setvbuf) then you can't 
merge.  Effectively, any change to any object whose address might have 
escaped should stop merging.

If anything evaluated might change what is pointed to by an argument to 
the first printf then you can't merge.  For example,

  char buf[] = "abc";
  printf("%s", buf);
  buf[0] = "d";
  printf("%s", buf);

cannot be merged.

If an argument or anything pointed to by an argument which is dereferenced 
and printed (e.g. %s) might have been changed by the first printf - if its 
address or the address it points to could have escaped - then you can't 
merge.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21982

Reply via email to