@@ -8376,22 +8376,27 @@ bool CheckScanfHandler::HandleScanfSpecifier(
83768376static void CompareFormatSpecifiers(Sema &S, const StringLiteral *Ref,
83778377 ArrayRef<EquatableFormatArgument> RefArgs,
83788378 const StringLiteral *Fmt,
8379- ArrayRef<EquatableFormatArgument> FmtArgs) {
8379+ ArrayRef<EquatableFormatArgument> FmtArgs,
8380+ const Expr *FmtExpr, bool InFunctionCall) {
83808381 unsigned CommonArgs;
8381- if (RefArgs.size() > FmtArgs.size()) {
8382- CommonArgs = FmtArgs.size();
8383- // "data argument not used by format string"
8384- const auto &Arg = RefArgs[FmtArgs.size()];
8385- S.Diag(Arg.getSourceLocation(), diag::warn_printf_data_arg_not_used)
8386- << Arg.getSourceRange();
8387- S.Diag(Fmt->getBeginLoc(), diag::note_format_cmp_with) << 1;
8388- } else if (FmtArgs.size() > RefArgs.size()) {
8382+ if (FmtArgs.size() > RefArgs.size()) {
83898383 CommonArgs = RefArgs.size();
8390- // "more % conversions than data arguments"
8391- const auto &Arg = FmtArgs[RefArgs.size()];
8392- S.Diag(Fmt->getBeginLoc(), diag::warn_format_cmp_insufficient_specifiers)
8393- << Arg.getSourceRange();
8384+ // "data argument not used by format string"
8385+ CheckFormatHandler::EmitFormatDiagnostic(
8386+ S, InFunctionCall, FmtExpr,
8387+ S.PDiag(diag::warn_format_cmp_specifier_arity) << 1,
8388+ FmtExpr->getBeginLoc(), false,
8389+ FmtArgs[RefArgs.size()].getSourceRange());
83948390 S.Diag(Ref->getBeginLoc(), diag::note_format_cmp_with) << 1;
8391+ } else if (RefArgs.size() > FmtArgs.size()) {
8392+ CommonArgs = FmtArgs.size();
8393+ // "fewer specifiers in format string than expected"
8394+ CheckFormatHandler::EmitFormatDiagnostic(
8395+ S, InFunctionCall, FmtExpr,
8396+ S.PDiag(diag::warn_format_cmp_specifier_arity) << 0,
8397+ FmtExpr->getBeginLoc(), false, Fmt->getSourceRange());
8398+ S.Diag(Ref->getBeginLoc(), diag::note_format_cmp_with)
8399+ << 1 << RefArgs[FmtArgs.size()].getSourceRange();
83958400 } else {
83968401 CommonArgs = FmtArgs.size();
83978402 }
@@ -8477,7 +8482,8 @@ static void CheckFormatString(
84778482 DecomposePrintfHandler::GetSpecifiers(S, FExpr, Type, IsObjC,
84788483 inFunctionCall, FmtArgs)) {
84798484 CompareFormatSpecifiers(S, ReferenceFormatString, RefArgs,
8480- FExpr->getFormatString(), FmtArgs);
8485+ FExpr->getFormatString(), FmtArgs,
8486+ Args[format_idx], inFunctionCall);
84818487 }
84828488 }
84838489 } else if (Type == Sema::FST_Scanf) {
0 commit comments