@@ -8376,22 +8376,27 @@ bool CheckScanfHandler::HandleScanfSpecifier(
8376
8376
static void CompareFormatSpecifiers(Sema &S, const StringLiteral *Ref,
8377
8377
ArrayRef<EquatableFormatArgument> RefArgs,
8378
8378
const StringLiteral *Fmt,
8379
- ArrayRef<EquatableFormatArgument> FmtArgs) {
8379
+ ArrayRef<EquatableFormatArgument> FmtArgs,
8380
+ const Expr *FmtExpr, bool InFunctionCall) {
8380
8381
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()) {
8389
8383
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());
8394
8390
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();
8395
8400
} else {
8396
8401
CommonArgs = FmtArgs.size();
8397
8402
}
@@ -8477,7 +8482,8 @@ static void CheckFormatString(
8477
8482
DecomposePrintfHandler::GetSpecifiers(S, FExpr, Type, IsObjC,
8478
8483
inFunctionCall, FmtArgs)) {
8479
8484
CompareFormatSpecifiers(S, ReferenceFormatString, RefArgs,
8480
- FExpr->getFormatString(), FmtArgs);
8485
+ FExpr->getFormatString(), FmtArgs,
8486
+ Args[format_idx], inFunctionCall);
8481
8487
}
8482
8488
}
8483
8489
} else if (Type == Sema::FST_Scanf) {
0 commit comments