<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Dec 17, 2007, at 9:30 AM, Ted Kremenek wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><br>On Dec 17, 2007, at 7:19 AM, Holger Schurig wrote:<br><br><blockquote type="cite">I'm not subscribed to clang mailing list, so not sure if my mail<br></blockquote><blockquote type="cite">comes throught. I'm reading the list via gmane.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I guess utilizing gcc  __attribute__((format(...))) would help<br></blockquote><blockquote type="cite">here. You could put that at the log<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">int logmessage(<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">   </span>int loglevel,<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">  </span>char const *fmt __attribute__ (format (printf, 2, 3))),<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">        </span>...) {<br></blockquote><blockquote type="cite">  // more code<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">That way the compiler knows that fmt *IS* a format string and<br></blockquote><blockquote type="cite">won't need to warn when it is used in vprintf().<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Code that calls logmessage() would know that fmt is a printf-like<br></blockquote><blockquote type="cite">format string and can check calls to logmessage. This attribute<br></blockquote><blockquote type="cite">would even help in the case of call-backs.<br></blockquote><br>I like this solution.  I think this would catch 90% of the correct  <br>cases, while suppressing most bogus messages.<br></blockquote><br></div><div>I just committed patch r45114 that partially implements this solution:</div><div><br class="webkit-block-placeholder"></div><div><a href="http://llvm.org/viewvc/llvm-project?rev=45114&view=rev">http://llvm.org/viewvc/llvm-project?rev=45114&view=rev</a></div><div><br class="webkit-block-placeholder"></div><div>Our support for attributes is still only preliminary, so right now I have coded the format string checker to not emit a warning if the format string for a vprintf-like function comes from the function parameter of the caller.  Later I will add the support to consult the attributes of the calling function to see if it should be treated like a printf function.</div></body></html>