@@ -7013,19 +7013,6 @@ bool Sema::CheckFormatString(const FormatMatchesAttr *Format,
70137013 return false;
70147014}
70157015
7016- std::string escapeFormatString(StringRef Input) {
7017- std::string Result;
7018- llvm::raw_string_ostream OS(Result);
7019- for (char C : Input) {
7020- StringRef Escaped = escapeCStyle<EscapeChar::Double>(C);
7021- if (Escaped.empty())
7022- OS << C;
7023- else
7024- OS << Escaped;
7025- }
7026- return Result;
7027- }
7028-
70297016static bool CheckMissingFormatAttribute(
70307017 Sema *S, ArrayRef<const Expr *> Args, Sema::FormatArgumentPassingKind APK,
70317018 StringLiteral *ReferenceFormatString, unsigned FormatIdx,
@@ -7094,15 +7081,17 @@ static bool CheckMissingFormatAttribute(
70947081 NamedDecl *ND = dyn_cast<NamedDecl>(Caller);
70957082 do {
70967083 std::string Attr, Fixit;
7097- if (APK != Sema::FormatArgumentPassingKind::FAPK_Elsewhere)
7098- llvm::raw_string_ostream(Attr)
7099- << "format(" << FormatTypeName << ", " << FormatStringIndex << ", "
7100- << FirstArgumentIndex << ")";
7101- else
7102- llvm::raw_string_ostream(Attr)
7103- << "format_matches(" << FormatTypeName << ", " << FormatStringIndex
7104- << ", \"" << escapeFormatString(ReferenceFormatString->getString())
7105- << "\")";
7084+ llvm::raw_string_ostream AttrOS(Attr);
7085+ if (APK != Sema::FormatArgumentPassingKind::FAPK_Elsewhere) {
7086+ AttrOS << "format(" << FormatTypeName << ", " << FormatStringIndex << ", "
7087+ << FirstArgumentIndex << ")";
7088+ } else {
7089+ AttrOS << "format_matches(" << FormatTypeName << ", " << FormatStringIndex
7090+ << ", \"";
7091+ AttrOS.write_escaped(ReferenceFormatString->getString());
7092+ AttrOS << "\")";
7093+ }
7094+ AttrOS.flush();
71067095 auto DB = S->Diag(Loc, diag::warn_missing_format_attribute) << Attr;
71077096 if (ND)
71087097 DB << ND;
0 commit comments