Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace android {
class AndroidModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<CloexecAccept4Check>("android-cloexec-accept4");
CheckFactories.registerCheck<CloexecAccept4Check>(
"android-cloexec-accept4");
CheckFactories.registerCheck<CloexecAcceptCheck>("android-cloexec-accept");
CheckFactories.registerCheck<CloexecCreatCheck>("android-cloexec-creat");
CheckFactories.registerCheck<CloexecDupCheck>("android-cloexec-dup");
Expand Down
9 changes: 4 additions & 5 deletions clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ void CloexecAcceptCheck::registerMatchers(MatchFinder *Finder) {
}

void CloexecAcceptCheck::check(const MatchFinder::MatchResult &Result) {
std::string ReplacementText =
(Twine("accept4(") + getSpellingArg(Result, 0) + ", " +
getSpellingArg(Result, 1) + ", " + getSpellingArg(Result, 2) +
", SOCK_CLOEXEC)")
.str();
std::string ReplacementText = (Twine("accept4(") + getSpellingArg(Result, 0) +
", " + getSpellingArg(Result, 1) + ", " +
getSpellingArg(Result, 2) + ", SOCK_CLOEXEC)")
.str();

replaceFunc(
Result,
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std::string buildFixMsgForStringFlag(const Expr *Arg, const SourceManager &SM,

const char *CloexecCheck::FuncDeclBindingStr = "funcDecl";

const char *CloexecCheck::FuncBindingStr ="func";
const char *CloexecCheck::FuncBindingStr = "func";

void CloexecCheck::registerMatchersImpl(
MatchFinder *Finder, internal::Matcher<FunctionDecl> Function) {
Expand Down
9 changes: 4 additions & 5 deletions clang-tools-extra/clang-tidy/android/CloexecCreatCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ namespace clang::tidy::android {
void CloexecCreatCheck::registerMatchers(MatchFinder *Finder) {
auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
auto MODETType = hasType(namedDecl(hasName("mode_t")));
registerMatchersImpl(Finder,
functionDecl(isExternC(), returns(isInteger()),
hasName("creat"),
hasParameter(0, CharPointerType),
hasParameter(1, MODETType)));
registerMatchersImpl(Finder, functionDecl(isExternC(), returns(isInteger()),
hasName("creat"),
hasParameter(0, CharPointerType),
hasParameter(1, MODETType)));
}

void CloexecCreatCheck::check(const MatchFinder::MatchResult &Result) {
Expand Down
9 changes: 4 additions & 5 deletions clang-tools-extra/clang-tidy/android/CloexecFopenCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ namespace clang::tidy::android {

void CloexecFopenCheck::registerMatchers(MatchFinder *Finder) {
auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
registerMatchersImpl(Finder,
functionDecl(isExternC(), returns(asString("FILE *")),
hasName("fopen"),
hasParameter(0, CharPointerType),
hasParameter(1, CharPointerType)));
registerMatchersImpl(
Finder, functionDecl(isExternC(), returns(asString("FILE *")),
hasName("fopen"), hasParameter(0, CharPointerType),
hasParameter(1, CharPointerType)));
}

void CloexecFopenCheck::check(const MatchFinder::MatchResult &Result) {
Expand Down
11 changes: 5 additions & 6 deletions clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) {
hasAnyName("open", "open64"),
hasParameter(0, CharPointerType),
hasParameter(1, hasType(isInteger()))));
registerMatchersImpl(Finder,
functionDecl(isExternC(), returns(isInteger()),
hasName("openat"),
hasParameter(0, hasType(isInteger())),
hasParameter(1, CharPointerType),
hasParameter(2, hasType(isInteger()))));
registerMatchersImpl(
Finder, functionDecl(isExternC(), returns(isInteger()), hasName("openat"),
hasParameter(0, hasType(isInteger())),
hasParameter(1, CharPointerType),
hasParameter(2, hasType(isInteger()))));
}

void CloexecOpenCheck::check(const MatchFinder::MatchResult &Result) {
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/clang-tidy/android/CloexecPipe2Check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ using namespace clang::ast_matchers;
namespace clang::tidy::android {

void CloexecPipe2Check::registerMatchers(MatchFinder *Finder) {
registerMatchersImpl(Finder,
functionDecl(returns(isInteger()), hasName("pipe2"),
hasParameter(0, hasType(pointsTo(isInteger()))),
hasParameter(1, hasType(isInteger()))));
registerMatchersImpl(
Finder, functionDecl(returns(isInteger()), hasName("pipe2"),
hasParameter(0, hasType(pointsTo(isInteger()))),
hasParameter(1, hasType(isInteger()))));
}

void CloexecPipe2Check::check(const MatchFinder::MatchResult &Result) {
Expand Down
14 changes: 7 additions & 7 deletions clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ using namespace clang::ast_matchers;
namespace clang::tidy::android {

void CloexecPipeCheck::registerMatchers(MatchFinder *Finder) {
registerMatchersImpl(Finder,
functionDecl(returns(isInteger()), hasName("pipe"),
hasParameter(0, hasType(pointsTo(isInteger())))));
registerMatchersImpl(
Finder, functionDecl(returns(isInteger()), hasName("pipe"),
hasParameter(0, hasType(pointsTo(isInteger())))));
}

void CloexecPipeCheck::check(const MatchFinder::MatchResult &Result) {
std::string ReplacementText =
(Twine("pipe2(") + getSpellingArg(Result, 0) + ", O_CLOEXEC)").str();

replaceFunc(
Result,
"prefer pipe2() with O_CLOEXEC to avoid leaking file descriptors to child processes",
ReplacementText);
replaceFunc(Result,
"prefer pipe2() with O_CLOEXEC to avoid leaking file descriptors "
"to child processes",
ReplacementText);
}

} // namespace clang::tidy::android
11 changes: 5 additions & 6 deletions clang-tools-extra/clang-tidy/android/CloexecSocketCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ using namespace clang::ast_matchers;
namespace clang::tidy::android {

void CloexecSocketCheck::registerMatchers(MatchFinder *Finder) {
registerMatchersImpl(Finder,
functionDecl(isExternC(), returns(isInteger()),
hasName("socket"),
hasParameter(0, hasType(isInteger())),
hasParameter(1, hasType(isInteger())),
hasParameter(2, hasType(isInteger()))));
registerMatchersImpl(
Finder, functionDecl(isExternC(), returns(isInteger()), hasName("socket"),
hasParameter(0, hasType(isInteger())),
hasParameter(1, hasType(isInteger())),
hasParameter(2, hasType(isInteger()))));
}

void CloexecSocketCheck::check(const MatchFinder::MatchResult &Result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
this);
}

void DynamicStaticInitializersCheck::check(const MatchFinder::MatchResult &Result) {
void DynamicStaticInitializersCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *Var = Result.Nodes.getNodeAs<VarDecl>("var");
SourceLocation Loc = Var->getLocation();
if (!Loc.isValid() || !utils::isPresumedLocInHeaderFile(Loc, *Result.SourceManager,
HeaderFileExtensions))
if (!Loc.isValid() || !utils::isPresumedLocInHeaderFile(
Loc, *Result.SourceManager, HeaderFileExtensions))
return;
// If the initializer is a constant expression, then the compiler
// doesn't have to dynamically initialize it.
diag(Loc, "static variable %0 may be dynamically initialized in this header file")
<< Var;
diag(Loc,
"static variable %0 may be dynamically initialized in this header file")
<< Var;
}

} // namespace clang::tidy::bugprone
12 changes: 5 additions & 7 deletions clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) {
const auto EndCall =
callExpr(
callee(functionDecl(hasAnyName("remove", "remove_if", "unique"))),
hasArgument(
1, optionally(cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"))))
.bind("end"))))
hasArgument(1, optionally(cxxMemberCallExpr(
callee(cxxMethodDecl(hasName("end"))))
.bind("end"))))
.bind("alg");

const auto DeclInStd = type(hasUnqualifiedDesugaredType(
Expand All @@ -35,10 +35,8 @@ void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) {
}

void InaccurateEraseCheck::check(const MatchFinder::MatchResult &Result) {
const auto *MemberCall =
Result.Nodes.getNodeAs<CXXMemberCallExpr>("erase");
const auto *EndExpr =
Result.Nodes.getNodeAs<CXXMemberCallExpr>("end");
const auto *MemberCall = Result.Nodes.getNodeAs<CXXMemberCallExpr>("erase");
const auto *EndExpr = Result.Nodes.getNodeAs<CXXMemberCallExpr>("end");
const SourceLocation Loc = MemberCall->getBeginLoc();

FixItHint Hint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===--- IncorrectRoundingsCheck.cpp - clang-tidy ------------------------------===//
//===--- IncorrectRoundingsCheck.cpp - clang-tidy--------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
9 changes: 4 additions & 5 deletions clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ static bool isVarThatIsPossiblyChanged(const Decl *Func, const Stmt *LoopStmt,
isChanged(LoopStmt, Var, Context);
// FIXME: Track references.
}
} else if (isa<MemberExpr, CallExpr,
ObjCIvarRefExpr, ObjCPropertyRefExpr, ObjCMessageExpr>(Cond)) {
} else if (isa<MemberExpr, CallExpr, ObjCIvarRefExpr, ObjCPropertyRefExpr,
ObjCMessageExpr>(Cond)) {
// FIXME: Handle MemberExpr.
return true;
} else if (const auto *CE = dyn_cast<CastExpr>(Cond)) {
Expand Down Expand Up @@ -274,8 +274,7 @@ static bool hasRecursionOverStaticLoopCondVariables(const Expr *Cond,

void InfiniteLoopCheck::registerMatchers(MatchFinder *Finder) {
const auto LoopCondition = allOf(
hasCondition(
expr(forCallable(decl().bind("func"))).bind("condition")),
hasCondition(expr(forCallable(decl().bind("func"))).bind("condition")),
unless(hasBody(hasDescendant(
loopEndingStmt(forCallable(equalsBoundNode("func")))))));

Expand Down Expand Up @@ -324,7 +323,7 @@ void InfiniteLoopCheck::check(const MatchFinder::MatchResult &Result) {
diag(LoopStmt->getBeginLoc(),
"this loop is infinite; none of its condition variables (%0)"
" are updated in the loop body")
<< CondVarNames;
<< CondVarNames;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ class MacroExpansionsWithFileAndLine : public PPCallbacks {
LambdaFunctionNameCheck::SourceRangeSet *SME)
: SuppressMacroExpansions(SME) {}

void MacroExpands(const Token &MacroNameTok,
const MacroDefinition &MD, SourceRange Range,
const MacroArgs *Args) override {
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
SourceRange Range, const MacroArgs *Args) override {
bool HasFile = false;
bool HasLine = false;
for (const auto& T : MD.getMacroInfo()->tokens()) {
for (const Token &T : MD.getMacroInfo()->tokens()) {
if (T.is(tok::identifier)) {
StringRef IdentName = T.getIdentifierInfo()->getName();
if (IdentName == "__FILE__") {
Expand All @@ -55,7 +54,7 @@ class MacroExpansionsWithFileAndLine : public PPCallbacks {
}

private:
LambdaFunctionNameCheck::SourceRangeSet* SuppressMacroExpansions;
LambdaFunctionNameCheck::SourceRangeSet *SuppressMacroExpansions;
};

AST_MATCHER(CXXMethodDecl, isInLambda) { return Node.getParent()->isLambda(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void MisplacedOperatorInStrlenInAllocCheck::check(
if (!Alloc)
Alloc = Result.Nodes.getNodeAs<CXXNewExpr>("Alloc");
assert(Alloc && "Matched node bound by 'Alloc' should be either 'CallExpr'"
" or 'CXXNewExpr'");
" or 'CXXNewExpr'");

const auto *StrLen = Result.Nodes.getNodeAs<CallExpr>("StrLen");
const auto *BinOp = Result.Nodes.getNodeAs<BinaryOperator>("BinOp");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace clang::tidy::bugprone {
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/misplaced-operator-in-strlen-in-alloc.html
class MisplacedOperatorInStrlenInAllocCheck : public ClangTidyCheck {
public:
MisplacedOperatorInStrlenInAllocCheck(StringRef Name, ClangTidyContext *Context)
MisplacedOperatorInStrlenInAllocCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ void MisplacedPointerArithmeticInAllocCheck::check(
} else {
const auto *CtrE = New->getConstructExpr();
if (!CtrE || !CtrE->getArg(CtrE->getNumArgs() - 1)
->getType()
->isIntegralOrEnumerationType())
->getType()
->isIntegralOrEnumerationType())
return;
CallName = "operator new";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ void MultipleNewInOneExpressionCheck::registerMatchers(MatchFinder *Finder) {

Finder->addMatcher(
callExpr(
hasAnyArgument(
expr(HasNewExpr1).bind("arg1")),
hasAnyArgument(expr(HasNewExpr1).bind("arg1")),
hasAnyArgument(
expr(HasNewExpr2, unless(equalsBoundNode("arg1"))).bind("arg2")),
hasAncestor(BadAllocCatchingTryBlock)),
this);
Finder->addMatcher(
cxxConstructExpr(
hasAnyArgument(
expr(HasNewExpr1).bind("arg1")),
hasAnyArgument(expr(HasNewExpr1).bind("arg1")),
hasAnyArgument(
expr(HasNewExpr2, unless(equalsBoundNode("arg1"))).bind("arg2")),
unless(isListInitialization()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ void NotNullTerminatedResultCheck::registerMatchers(MatchFinder *Finder) {
std::optional<unsigned> SourcePos, unsigned LengthPos,
bool WithIncrease)
: Name(Name), DestinationPos(DestinationPos), SourcePos(SourcePos),
LengthPos(LengthPos), WithIncrease(WithIncrease){};
LengthPos(LengthPos), WithIncrease(WithIncrease) {};

StringRef Name;
std::optional<unsigned> DestinationPos;
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace clang::tidy::bugprone {

class PosixReturnCheck: public ClangTidyCheck {
class PosixReturnCheck : public ClangTidyCheck {
public:
PosixReturnCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===--- RedundantBranchConditionCheck.cpp - clang-tidy -------------------------===//
//===--- RedundantBranchConditionCheck.cpp - clang-tidy--------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down Expand Up @@ -70,7 +70,8 @@ void RedundantBranchConditionCheck::registerMatchers(MatchFinder *Finder) {
// FIXME: Handle longer conjunctive and disjunctive clauses.
}

void RedundantBranchConditionCheck::check(const MatchFinder::MatchResult &Result) {
void RedundantBranchConditionCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *OuterIf = Result.Nodes.getNodeAs<IfStmt>(OuterIfStr);
const auto *InnerIf = Result.Nodes.getNodeAs<IfStmt>(InnerIfStr);
const auto *CondVar = Result.Nodes.getNodeAs<VarDecl>(CondVarStr);
Expand Down
12 changes: 8 additions & 4 deletions clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ constexpr llvm::StringLiteral MinimalConformingFunctions[] = {
// mentioned POSIX specification was not updated after 'quick_exit' appeared
// in the C11 standard.
// Also, we want to keep the "minimal set" a subset of the "POSIX set".
// The list is repeated in bugprone-signal-handler.rst and should be kept up to date.
// The list is repeated in bugprone-signal-handler.rst and should be kept up to
// date.
// clang-format off
constexpr llvm::StringLiteral POSIXConformingFunctions[] = {
"_Exit",
"_exit",
Expand Down Expand Up @@ -215,7 +217,9 @@ constexpr llvm::StringLiteral POSIXConformingFunctions[] = {
"wmemcpy",
"wmemmove",
"wmemset",
"write"};
"write"
};
// clang-format on

using namespace clang::ast_matchers;

Expand Down Expand Up @@ -322,12 +326,12 @@ SourceRange getSourceRangeOfStmt(const Stmt *S, ASTContext &Ctx) {
return P.getSourceRange();
}

} // namespace

AST_MATCHER(FunctionDecl, isStandardFunction) {
return isStandardFunction(&Node);
}

} // namespace

SignalHandlerCheck::SignalHandlerCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace clang::tidy::bugprone {

/// Finds ``cnd_wait``, ``cnd_timedwait``, ``wait``, ``wait_for``, or
/// ``wait_until`` function calls when the function is not invoked from a loop
/// that checks whether a condition predicate holds or the function has a
/// Finds ``cnd_wait``, ``cnd_timedwait``, ``wait``, ``wait_for``, or
/// ``wait_until`` function calls when the function is not invoked from a loop
/// that checks whether a condition predicate holds or the function has a
/// condition parameter.
///
/// For the user-facing documentation see:
Expand Down
Loading
Loading