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
12 changes: 4 additions & 8 deletions clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ using namespace clang::ast_matchers;

namespace clang::tidy::android {

namespace {
// Helper function to form the correct string mode for Type3.
// Build the replace text. If it's string constant, add <Mode> directly in the
// end of the string. Else, add <Mode>.
std::string buildFixMsgForStringFlag(const Expr *Arg, const SourceManager &SM,
const LangOptions &LangOpts, char Mode) {
static std::string buildFixMsgForStringFlag(const Expr *Arg,
const SourceManager &SM,
const LangOptions &LangOpts,
char Mode) {
if (Arg->getBeginLoc().isMacroID())
return (Lexer::getSourceText(
CharSourceRange::getTokenRange(Arg->getSourceRange()), SM,
Expand All @@ -32,11 +33,6 @@ std::string buildFixMsgForStringFlag(const Expr *Arg, const SourceManager &SM,
StringRef SR = cast<StringLiteral>(Arg->IgnoreParenCasts())->getString();
return ("\"" + SR + Twine(Mode) + "\"").str();
}
} // namespace

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

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

void CloexecCheck::registerMatchersImpl(
MatchFinder *Finder, internal::Matcher<FunctionDecl> Function) {
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/android/CloexecCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class CloexecCheck : public ClangTidyCheck {
int N) const;

/// Binding name of the FuncDecl of a function call.
static const char *FuncDeclBindingStr;
static constexpr char FuncDeclBindingStr[] = "funcDecl";

/// Binding name of the function call expression.
static const char *FuncBindingStr;
static constexpr char FuncBindingStr[] = "func";
};

} // namespace clang::tidy::android
Expand Down
19 changes: 9 additions & 10 deletions clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,10 @@ struct OptionEnumMapping<

namespace bugprone {

namespace {

/// Returns if a function is declared inside a system header.
/// These functions are considered to be "standard" (system-provided) library
/// functions.
bool isStandardFunction(const FunctionDecl *FD) {
static bool isStandardFunction(const FunctionDecl *FD) {
// Find a possible redeclaration in system header.
// FIXME: Looking at the canonical declaration is not the most exact way
// to do this.
Expand Down Expand Up @@ -284,7 +282,7 @@ bool isStandardFunction(const FunctionDecl *FD) {
/// Check if a statement is "C++-only".
/// This includes all statements that have a class name with "CXX" prefix
/// and every other statement that is declared in file ExprCXX.h.
bool isCXXOnlyStmt(const Stmt *S) {
static bool isCXXOnlyStmt(const Stmt *S) {
StringRef Name = S->getStmtClassName();
if (Name.starts_with("CXX"))
return true;
Expand All @@ -304,7 +302,8 @@ bool isCXXOnlyStmt(const Stmt *S) {
/// called from \p Caller, get a \c CallExpr of the corresponding function call.
/// It is unspecified which call is found if multiple calls exist, but the order
/// should be deterministic (depend only on the AST).
Expr *findCallExpr(const CallGraphNode *Caller, const CallGraphNode *Callee) {
static Expr *findCallExpr(const CallGraphNode *Caller,
const CallGraphNode *Callee) {
const auto *FoundCallee = llvm::find_if(
Caller->callees(), [Callee](const CallGraphNode::CallRecord &Call) {
return Call.Callee == Callee;
Expand All @@ -314,7 +313,7 @@ Expr *findCallExpr(const CallGraphNode *Caller, const CallGraphNode *Callee) {
return FoundCallee->CallExpr;
}

SourceRange getSourceRangeOfStmt(const Stmt *S, ASTContext &Ctx) {
static SourceRange getSourceRangeOfStmt(const Stmt *S, ASTContext &Ctx) {
ParentMapContext &PM = Ctx.getParentMapContext();
DynTypedNode P = DynTypedNode::create(*S);
while (P.getSourceRange().isInvalid()) {
Expand All @@ -326,9 +325,9 @@ SourceRange getSourceRangeOfStmt(const Stmt *S, ASTContext &Ctx) {
return P.getSourceRange();
}

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

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

} // namespace

Expand All @@ -354,7 +353,7 @@ bool SignalHandlerCheck::isLanguageVersionSupported(

void SignalHandlerCheck::registerMatchers(MatchFinder *Finder) {
auto SignalFunction = functionDecl(hasAnyName("::signal", "::std::signal"),
parameterCountIs(2), isStandardFunction());
parameterCountIs(2), isStandard());
auto HandlerExpr =
declRefExpr(hasDeclaration(functionDecl().bind("handler_decl")),
unless(isExpandedFromMacro("SIG_IGN")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ using namespace clang::ast_matchers;
using namespace clang::tidy::matchers;

namespace clang::tidy::misc {
namespace {
using llvm::APSInt;

static constexpr llvm::StringLiteral KnownBannedMacroNames[] = {
Expand Down Expand Up @@ -420,6 +419,8 @@ markDuplicateOperands(const TExpr *TheExpr,
return Duplicates.any();
}

namespace {

AST_MATCHER(Expr, isIntegerConstantExpr) {
if (Node.isInstantiationDependent())
return false;
Expand Down Expand Up @@ -470,6 +471,8 @@ AST_MATCHER_P(Expr, expandedByMacro, ArrayRef<llvm::StringLiteral>, Names) {
return false;
}

} // namespace

// Returns a matcher for integer constant expressions.
static ast_matchers::internal::Matcher<Expr>
matchIntegerConstantExpr(StringRef Id) {
Expand Down Expand Up @@ -805,7 +808,8 @@ static bool isSameRawIdentifierToken(const Token &T1, const Token &T2,
StringRef(SM.getCharacterData(T2.getLocation()), T2.getLength());
}

bool isTokAtEndOfExpr(SourceRange ExprSR, Token T, const SourceManager &SM) {
static bool isTokAtEndOfExpr(SourceRange ExprSR, Token T,
const SourceManager &SM) {
return SM.getExpansionLoc(ExprSR.getEnd()) == T.getLocation();
}

Expand Down Expand Up @@ -921,7 +925,6 @@ static bool areExprsSameMacroOrLiteral(const BinaryOperator *BinOp,

return false;
}
} // namespace

void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
const auto BannedIntegerLiteral =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ void UniqueptrResetReleaseCheck::registerMatchers(MatchFinder *Finder) {
this);
}

namespace {
const Type *getDeleterForUniquePtr(const MatchFinder::MatchResult &Result,
StringRef ID) {
static const Type *
getDeleterForUniquePtr(const MatchFinder::MatchResult &Result, StringRef ID) {
const auto *Class =
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>(ID);
if (!Class)
Expand All @@ -66,7 +65,7 @@ const Type *getDeleterForUniquePtr(const MatchFinder::MatchResult &Result,
return DeleterArgument.getAsType().getTypePtr();
}

bool areDeletersCompatible(const MatchFinder::MatchResult &Result) {
static bool areDeletersCompatible(const MatchFinder::MatchResult &Result) {
const Type *LeftDeleterType = getDeleterForUniquePtr(Result, "left_class");
const Type *RightDeleterType = getDeleterForUniquePtr(Result, "right_class");

Expand Down Expand Up @@ -103,8 +102,6 @@ bool areDeletersCompatible(const MatchFinder::MatchResult &Result) {
return false;
}

} // namespace

void UniqueptrResetReleaseCheck::check(const MatchFinder::MatchResult &Result) {
if (!areDeletersCompatible(Result))
return;
Expand Down
24 changes: 15 additions & 9 deletions clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ using namespace llvm;
namespace clang::tidy::modernize {
namespace {

const char CastSequence[] = "sequence";

AST_MATCHER(Type, sugaredNullptrType) {
const Type *DesugaredType = Node.getUnqualifiedDesugaredType();
if (const auto *BT = dyn_cast<BuiltinType>(DesugaredType))
return BT->getKind() == BuiltinType::NullPtr;
return false;
}

} // namespace

static const char CastSequence[] = "sequence";

/// Create a matcher that finds implicit casts as well as the head of a
/// sequence of zero or more nested explicit casts that have an implicit cast
/// to null within.
Expand All @@ -43,7 +45,8 @@ AST_MATCHER(Type, sugaredNullptrType) {
/// would check for the "NULL" macro instead, but that'd be harder to express.
/// In practice, "NULL" is often defined as "__null", and this is a useful
/// condition.
StatementMatcher makeCastSequenceMatcher(llvm::ArrayRef<StringRef> NameList) {
static StatementMatcher
makeCastSequenceMatcher(llvm::ArrayRef<StringRef> NameList) {
auto ImplicitCastToNull = implicitCastExpr(
anyOf(hasCastKind(CK_NullToPointer), hasCastKind(CK_NullToMemberPointer)),
anyOf(hasSourceExpression(gnuNullExpr()),
Expand Down Expand Up @@ -79,16 +82,16 @@ StatementMatcher makeCastSequenceMatcher(llvm::ArrayRef<StringRef> NameList) {
unless(hasAncestor(functionDecl(isDefaulted()))))));
}

bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
const SourceManager &SM) {
static bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
const SourceManager &SM) {
return SM.isWrittenInSameFile(StartLoc, EndLoc);
}

/// Replaces the provided range with the text "nullptr", but only if
/// the start and end location are both in main file.
/// Returns true if and only if a replacement was made.
void replaceWithNullptr(ClangTidyCheck &Check, SourceManager &SM,
SourceLocation StartLoc, SourceLocation EndLoc) {
static void replaceWithNullptr(ClangTidyCheck &Check, SourceManager &SM,
SourceLocation StartLoc, SourceLocation EndLoc) {
CharSourceRange Range(SourceRange(StartLoc, EndLoc), true);
// Add a space if nullptr follows an alphanumeric character. This happens
// whenever there is an c-style explicit cast to nullptr not surrounded by
Expand All @@ -106,8 +109,9 @@ void replaceWithNullptr(ClangTidyCheck &Check, SourceManager &SM,
/// #define MY_NULL NULL
/// \endcode
/// If \p Loc points to NULL, this function will return the name MY_NULL.
StringRef getOutermostMacroName(SourceLocation Loc, const SourceManager &SM,
const LangOptions &LO) {
static StringRef getOutermostMacroName(SourceLocation Loc,
const SourceManager &SM,
const LangOptions &LO) {
assert(Loc.isMacroID());
SourceLocation OutermostMacroLoc;

Expand All @@ -119,6 +123,8 @@ StringRef getOutermostMacroName(SourceLocation Loc, const SourceManager &SM,
return Lexer::getImmediateMacroName(OutermostMacroLoc, SM, LO);
}

namespace {

/// RecursiveASTVisitor for ensuring all nodes rooted at a given AST
/// subtree that have file-level source locations corresponding to a macro
/// argument have implicit NullTo(Member)Pointer nodes as ancestors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ using namespace clang::ast_matchers;

namespace clang::tidy::performance {

namespace {

std::optional<std::string> makeCharacterLiteral(const StringLiteral *Literal) {
static std::optional<std::string>
makeCharacterLiteral(const StringLiteral *Literal) {
std::string Result;
{
llvm::raw_string_ostream OS(Result);
Expand All @@ -43,6 +42,8 @@ std::optional<std::string> makeCharacterLiteral(const StringLiteral *Literal) {
return Result;
}

namespace {

AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<Expr>,
hasSubstitutedType) {
return hasType(qualType(anyOf(substTemplateTypeParmType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ using namespace clang::ast_matchers;

namespace clang::tidy::performance {

namespace {

// Matcher names. Given the code:
//
// \code
Expand Down Expand Up @@ -60,12 +58,14 @@ static const char LoopInitVarName[] = "loop_init_var";
static const char LoopEndExprName[] = "loop_end_expr";
static const char RangeLoopName[] = "for_range_loop";

ast_matchers::internal::Matcher<Expr> supportedContainerTypesMatcher() {
static ast_matchers::internal::Matcher<Expr> supportedContainerTypesMatcher() {
return hasType(cxxRecordDecl(hasAnyName(
"::std::vector", "::std::set", "::std::unordered_set", "::std::map",
"::std::unordered_map", "::std::array", "::std::deque")));
}

namespace {

AST_MATCHER(Expr, hasSideEffects) {
return Node.HasSideEffects(Finder->getASTContext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class DuplicateIncludeCallbacks : public PPCallbacks {
const SourceManager &SM;
};

} // namespace

void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
Expand Down Expand Up @@ -107,8 +109,6 @@ void DuplicateIncludeCallbacks::MacroUndefined(const Token &MacroNameTok,
Files.back().clear();
}

} // namespace

void DuplicateIncludeCheck::registerPPCallbacks(
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
PP->addPPCallbacks(std::make_unique<DuplicateIncludeCallbacks>(*this, SM));
Expand Down
Loading