Skip to content

Commit 9a0a509

Browse files
committed
Cleanup
1 parent f1f719c commit 9a0a509

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ Improvements to Clang's diagnostics
401401
or continue (#GH166013)
402402
- Clang now emits a diagnostic in case `vector_size` or `ext_vector_type`
403403
attributes are used with a negative size (#GH165463).
404-
- Clang now detects potential missing format attributes on function declarations
405-
when calling format functions. (#GH60718)
404+
- Clang now detects potential missing format and format_matches attributes on function,
405+
Objective-C method and block declarations when calling format functions. It is part
406+
of the format-nonliteral diagnostic (#GH60718)
406407

407408
Improvements to Clang's time-trace
408409
----------------------------------

clang/lib/Sema/SemaChecking.cpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
70297016
static 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

Comments
 (0)