<div class="gmail_quote">On Thu, Oct 13, 2011 at 2:53 PM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="HOEnZb"><div class="h5">On Thu, Oct 13, 2011 at 2:38 PM, Richard Trieu <<a href="mailto:rtrieu@google.com">rtrieu@google.com</a>> wrote:<br>
> <a href="http://llvm.org/bugs/show_bug.cgi?id=9751" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=9751</a><br>
> -Wformat warnings will point to the format string, but no message at the<br>
> call site.  This patch will move the warning to always point at the call<br>
> site.  If the format string is part of the function call, one warning will<br>
> show.  If the format string is defined elsewhere, a warning at the call site<br>
> plus a note where the format string is defined.<br>
> Also, if a note is present, the fix-it would be moved to the note so they<br>
> won't be applied with -fixit.  If the format string was used in multiple<br>
> places, fixits may cause problems in other places.<br>
> printf("%d %d", 1);<br>
> warning: more '%' conversions than data arguments [-Wformat]<br>
> printf("%d %d", 1);<br>
>            ~^<br>
> const char kFormat[] = "%d %d";<br>
> printf(kFormat, 1);<br>
> test2.c:8:8: warning: more '%' conversions than data arguments [-Wformat]<br>
> printf(kFormat, 1);<br>
>        ^~~~~~~<br>
> test2.c:7:29: note: format string is defined here<br>
> const char kFormat[] = "%d %d";<br>
>                            ~^<br>
> Patch attached an available at <a href="http://codereview.appspot.com/5277043/" target="_blank">http://codereview.appspot.com/5277043/</a><br>
<br>
</div></div>+namespace {<br>
+  class StringLiteralFinder<br>
+    : public ConstStmtVisitor<StringLiteralFinder> {<br>
+    Sema& S;<br>
+    const StringLiteral *StringExpr;<br>
+    bool StringFound;<br>
+  public:<br>
[...]<br>
<br>
Why is StringLiteralFinder necessary?  The caller should know how it<br>
found the string literal...<br>
<br></blockquote><div>That information isn't currently preserved through the diagnostics.  The StringLiteralFinder is necessary to determine this after the fact.  I can go look again and see if I can propagate that bit of info through the code.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
What do the resulting diagnostics look like if the string literal is<br>
defined in a macro?<br></blockquote><div><br></div><div>Like this:</div><div><br></div><div>#define FORMAT "%d %d"</div><div><br></div><div>void printf_test() {</div><div>  printf(FORMAT, 1);</div><div>}</div><div>
<br></div><div><div>test2.c:11:8: warning: more '%' conversions than data arguments [-Wformat]</div><div>  printf(FORMAT, 1);</div><div>         ^</div><div>test2.c:4:21: note: expanded from:</div><div>#define FORMAT "%d %d"</div>
<div>                   ~^</div><div>1 warning generated.</div></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<span class="HOEnZb"><font color="#888888"><br>
-Eli<br>
</font></span></blockquote></div><br>