On Mon, Jan 02, 2017 at 03:51:14PM -0700, Martin Sebor wrote: > On 01/02/2017 12:36 PM, Jakub Jelinek wrote: > > Hi! > > > > Even when we know the exact return value of a snprintf call with 0 length > > (i.e. one that doesn't write anything into a buffer), there can be %n > > directives in the format string that have side-effects that shouldn't be > > discarded. > > > > The following patch avoids the replacement of the snprintf call > > with just the constant if there is any %n directive. > > > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > Thanks. The fix looks good to me. I would suggest to also update > the comment above the nowrite member to say something like this: > > /* True for bounded functions like snprintf that specify a zero-size > buffer as a request to compute the size of output without actually > writing any. NOWRITE is cleared in response to the %n directive > which has side-effects similar to writing output. */
LGTM, thanks. I'll adjust the comment if it is approved. > > 2017-01-02 Jakub Jelinek <ja...@redhat.com> > > > > PR tree-optimization/78965 > > * gimple-ssa-sprintf.c (pass_sprintf_length::compute_format_length): > > Change first argument from const call_info & to call_info &. For %n > > set info.nowrite to false. > > > > * gcc.dg/pr78965.c: New test. Jakub