<div>Hi</div><div><br></div><div>I've started looking at printf correspondence between conversion specifier and arguments.</div><div><br></div>
<div>1/ Am I on the right track with the patch below?</div><div><br></div><div>2/ Assuming an affirmative answer on (1), I'm not sure how to define a new warning (I used warn_printf_asterisk_width_wrong_type which is wrong in this case).</div>
<div>I'm guessing defs are in include/clang/Basic/DiagnosticSemaKinds.inc and .td and referred in DiagnosticGroups.inc and .td</div><div>A new diagnostic would be needed, along the lines of "conversion specifies type 'X', but argument has type 'Y'"</div>
<div><br></div><div><br></div><div>Thanks for your time,</div>
<div>Cristi</div><div><br></div><div><br></div><div><div>cristi:clang diciu$ svn diff ./lib/Sema/SemaChecking.cpp</div><div>Index: lib/Sema/SemaChecking.cpp</div><div>===================================================================</div>
<div>--- lib/Sema/SemaChecking.cpp<span class="Apple-tab-span" style="white-space:pre"> </span>(revision 93981)</div><div>+++ lib/Sema/SemaChecking.cpp<span class="Apple-tab-span" style="white-space:pre"> </span>(working copy)</div>
<div>@@ -1147,7 +1147,17 @@</div><div> //</div><div> // FIXME: additional checks will go into the following cases.</div><div> case 'i':</div><div>- case 'd':</div><div>+ case 'd': {</div>
<div>+ if(numDataArgs >= format_idx+numConversions+1) {</div><div>+ const Expr *E2 = TheCall->getArg(format_idx+numConversions+1);</div><div>+ const BuiltinType *BT = E2->getType()->getAs<BuiltinType>();</div>
<div>+ if(BT == NULL || BT->getKind() != BuiltinType::Int) {</div><div>+ SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx);</div><div>+ Diag(Loc, diag::warn_printf_asterisk_width_wrong_type)</div>
<div>+ << E2->getType() << E2->getSourceRange();</div><div>+ }</div><div>+ }</div><div>+ }</div><div> case 'o':</div><div> case 'u':</div><div> case 'x':</div>
<div><br></div></div><div><div><br></div><br>
</div>