Skip to content
Open
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
1 change: 0 additions & 1 deletion clang-tools-extra/clang-tidy/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Checks: >
performance-*,
-performance-enum-size,
-performance-no-int-to-ptr,
-performance-unnecessary-value-param,
readability-*,
-readability-avoid-nested-conditional-operator,
-readability-braces-around-statements,
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/ClangTidy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ ClangTidyASTConsumerFactory::createASTConsumer(

if (Context.canEnableModuleHeadersParsing() &&
Context.getLangOpts().Modules && OverlayFS != nullptr) {
auto ModuleExpander =
std::make_unique<ExpandModularHeadersPPCallbacks>(&Compiler, OverlayFS);
auto ModuleExpander = std::make_unique<ExpandModularHeadersPPCallbacks>(
&Compiler, *OverlayFS);
ModuleExpanderPP = ModuleExpander->getPreprocessor();
PP->addPPCallbacks(std::move(ModuleExpander));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
};

ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
CompilerInstance *CI,
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
CompilerInstance *CI, llvm::vfs::OverlayFileSystem &OverlayFS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could we know that original object of OverlayFileSystem & will outlive this reference. From docs I assume that IntrusiveRefCntPtr has shared_ptr semantics but this convertion to reference seems bugprone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be easier to accept if we write const IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>& or move the pointer

Copy link
Contributor Author

@localspook localspook Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s possible that the referenced object is destroyed right after this function ends, but that’s okay, because this function doesn’t store the reference anywhere, so it can’t dangle. The equation doesn’t change even if the function takes an IntrusiveRefCntPtr: it could be the last pointer to this object, so when the function ends, the pointed-to object is destroyed. Same argument applies to the other case below.

: Recorder(std::make_unique<FileRecorder>()), Compiler(*CI),
InMemoryFs(new llvm::vfs::InMemoryFileSystem),
Sources(Compiler.getSourceManager()),
Expand All @@ -76,7 +75,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
LangOpts(Compiler.getLangOpts()), HSOpts(Compiler.getHeaderSearchOpts()) {
// Add a FileSystem containing the extra files needed in place of modular
// headers.
OverlayFS->pushOverlay(InMemoryFs);
OverlayFS.pushOverlay(InMemoryFs);

Diags.setSourceManager(&Sources);
// FIXME: Investigate whatever is there better way to initialize DiagEngine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ namespace tooling {
/// non-modular way.
class ExpandModularHeadersPPCallbacks : public PPCallbacks {
public:
ExpandModularHeadersPPCallbacks(
CompilerInstance *CI,
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS);
ExpandModularHeadersPPCallbacks(CompilerInstance *CI,
llvm::vfs::OverlayFileSystem &OverlayFS);
~ExpandModularHeadersPPCallbacks();

/// Returns the preprocessor that provides callbacks for the whole
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 @@ -39,7 +39,7 @@ const char *CloexecCheck::FuncDeclBindingStr = "funcDecl";
const char *CloexecCheck::FuncBindingStr = "func";

void CloexecCheck::registerMatchersImpl(
MatchFinder *Finder, internal::Matcher<FunctionDecl> Function) {
MatchFinder *Finder, const internal::Matcher<FunctionDecl> &Function) {
// We assume all the checked APIs are C functions.
Finder->addMatcher(
callExpr(
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clang-tidy/android/CloexecCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class CloexecCheck : public ClangTidyCheck {
: ClangTidyCheck(Name, Context) {}

protected:
void
registerMatchersImpl(ast_matchers::MatchFinder *Finder,
ast_matchers::internal::Matcher<FunctionDecl> Function);
void registerMatchersImpl(
ast_matchers::MatchFinder *Finder,
const ast_matchers::internal::Matcher<FunctionDecl> &Function);

/// Currently, we have three types of fixes.
///
Expand Down
5 changes: 3 additions & 2 deletions clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <initializer_list>
#include <optional>
#include <string>
#include <utility>

// FixItHint - Let the docs script know that this class does provide fixits

Expand Down Expand Up @@ -217,11 +218,11 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
const auto AddFromStd =
[&](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
std::initializer_list<StringRef> Names) {
AddFrom(Replacer, Names, "std");
AddFrom(std::move(Replacer), Names, "std");
};

const auto AddFromBoost =
[&](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
[&](const llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> &Replacer,
std::initializer_list<
std::pair<StringRef, std::initializer_list<StringRef>>>
NamespaceAndNames) {
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ void SignalHandlerCheck::check(const MatchFinder::MatchResult &Result) {

bool SignalHandlerCheck::checkFunction(
const FunctionDecl *FD, const Expr *CallOrRef,
std::function<void(bool)> ChainReporter) {
llvm::function_ref<void(bool)> ChainReporter) {
bool FunctionIsCalled = isa<CallExpr>(CallOrRef);

if (isStandardFunction(FD)) {
Expand Down Expand Up @@ -471,7 +471,7 @@ bool SignalHandlerCheck::checkFunction(

bool SignalHandlerCheck::checkFunctionCPP14(
const FunctionDecl *FD, const Expr *CallOrRef,
std::function<void(bool)> ChainReporter) {
llvm::function_ref<void(bool)> ChainReporter) {
if (!FD->isExternC()) {
diag(CallOrRef->getBeginLoc(),
"functions without C linkage are not allowed as signal "
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class SignalHandlerCheck : public ClangTidyCheck {
/// The bool parameter is used like \c SkipPathEnd in \c reportHandlerChain .
/// \return Returns true if a diagnostic was emitted for this function.
bool checkFunction(const FunctionDecl *FD, const Expr *CallOrRef,
std::function<void(bool)> ChainReporter);
llvm::function_ref<void(bool)> ChainReporter);
/// Similar as \c checkFunction but only check for C++14 rules.
bool checkFunctionCPP14(const FunctionDecl *FD, const Expr *CallOrRef,
std::function<void(bool)> ChainReporter);
llvm::function_ref<void(bool)> ChainReporter);
/// Returns true if a standard library function is considered
/// asynchronous-safe.
bool isStandardFunctionAsyncSafe(const FunctionDecl *FD) const;
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ void UnusedRaiiCheck::registerMatchers(MatchFinder *Finder) {
}

template <typename T>
static void reportDiagnostic(DiagnosticBuilder D, const T *Node, SourceRange SR,
bool DefaultConstruction) {
static void reportDiagnostic(const DiagnosticBuilder &D, const T *Node,
SourceRange SR, bool DefaultConstruction) {
const char *Replacement = " give_me_a_name";

// If this is a default ctor we have to remove the parens or we'll introduce a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void NonTrivialTypesLibcMemoryCallsCheck::storeOptions(
void NonTrivialTypesLibcMemoryCallsCheck::registerMatchers(
MatchFinder *Finder) {
using namespace ast_matchers::internal;
auto IsStructPointer = [](Matcher<CXXRecordDecl> Constraint = anything(),
auto IsStructPointer = [](const Matcher<CXXRecordDecl> &Constraint =
anything(),
bool Bind = false) {
return expr(unaryOperator(
hasOperatorName("&"),
Expand All @@ -76,7 +77,7 @@ void NonTrivialTypesLibcMemoryCallsCheck::registerMatchers(
auto IsRecordSizeOf =
expr(sizeOfExpr(hasArgumentOfType(equalsBoundNode("Record"))));
auto ArgChecker = [&](Matcher<CXXRecordDecl> RecordConstraint,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strange: why Matcher<CXXRecordDecl> isn't converted to reference but BindableMatcher<Stmt> is converted. Above, we converted Matcher<CXXRecordDecl> to reference already.

BindableMatcher<Stmt> SecondArg = expr()) {
const BindableMatcher<Stmt> &SecondArg = expr()) {
return allOf(argumentCountIs(3),
hasArgument(0, IsStructPointer(RecordConstraint, true)),
hasArgument(1, SecondArg), hasArgument(2, IsRecordSizeOf));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct DenseMapInfo<
"TOMBSTONE"};
}

static unsigned getHashValue(ClassDefId Val) {
static unsigned getHashValue(const ClassDefId &Val) {
assert(Val != getEmptyKey() && "Cannot hash the empty key!");
assert(Val != getTombstoneKey() && "Cannot hash the tombstone key!");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ namespace {
class RestrictedIncludesPPCallbacks
: public portability::RestrictedIncludesPPCallbacks {
public:
explicit RestrictedIncludesPPCallbacks(
RestrictSystemLibcHeadersCheck &Check, const SourceManager &SM,
const SmallString<128> CompilerIncudeDir)
explicit RestrictedIncludesPPCallbacks(RestrictSystemLibcHeadersCheck &Check,
const SourceManager &SM,
SmallString<128> CompilerIncudeDir)
: portability::RestrictedIncludesPPCallbacks(Check, SM),
CompilerIncudeDir(CompilerIncudeDir) {}
CompilerIncudeDir(std::move(CompilerIncudeDir)) {}

void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
Expand Down Expand Up @@ -61,7 +61,7 @@ void RestrictSystemLibcHeadersCheck::registerPPCallbacks(
StringRef(PP->getHeaderSearchInfo().getHeaderSearchOpts().ResourceDir);
llvm::sys::path::append(CompilerIncudeDir, "include");
PP->addPPCallbacks(std::make_unique<RestrictedIncludesPPCallbacks>(
*this, SM, CompilerIncudeDir));
*this, SM, std::move(CompilerIncudeDir)));
}

} // namespace clang::tidy::llvm_libc
Original file line number Diff line number Diff line change
Expand Up @@ -1144,16 +1144,18 @@ void RedundantExpressionCheck::checkArithmeticExpr(
}
}

static bool exprEvaluatesToZero(BinaryOperatorKind Opcode, APSInt Value) {
static bool exprEvaluatesToZero(BinaryOperatorKind Opcode,
const APSInt &Value) {
return (Opcode == BO_And || Opcode == BO_AndAssign) && Value == 0;
}

static bool exprEvaluatesToBitwiseNegatedZero(BinaryOperatorKind Opcode,
APSInt Value) {
const APSInt &Value) {
return (Opcode == BO_Or || Opcode == BO_OrAssign) && ~Value == 0;
}

static bool exprEvaluatesToSymbolic(BinaryOperatorKind Opcode, APSInt Value) {
static bool exprEvaluatesToSymbolic(BinaryOperatorKind Opcode,
const APSInt &Value) {
return ((Opcode == BO_Or || Opcode == BO_OrAssign) && Value == 0) ||
((Opcode == BO_And || Opcode == BO_AndAssign) && ~Value == 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static StatementMatcher incrementVarMatcher() {
}

static StatementMatcher
arrayConditionMatcher(internal::Matcher<Expr> LimitExpr) {
arrayConditionMatcher(const internal::Matcher<Expr> &LimitExpr) {
return binaryOperator(
anyOf(allOf(hasOperatorName("<"), hasLHS(integerComparisonMatcher()),
hasRHS(LimitExpr)),
Expand Down
11 changes: 6 additions & 5 deletions clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ AST_MATCHER_P(clang::Expr, anyOfExhaustive, std::vector<Matcher<clang::Stmt>>,
// literals.
struct MatchBuilder {
auto
ignoreParenAndArithmeticCasting(const Matcher<clang::Expr> Matcher) const {
ignoreParenAndArithmeticCasting(const Matcher<clang::Expr> &Matcher) const {
return expr(hasType(qualType(isArithmetic())), ignoringParenCasts(Matcher));
}

auto ignoreParenAndFloatingCasting(const Matcher<clang::Expr> Matcher) const {
auto
ignoreParenAndFloatingCasting(const Matcher<clang::Expr> &Matcher) const {
return expr(hasType(qualType(isFloating())), ignoringParenCasts(Matcher));
}

auto matchMathCall(const StringRef FunctionName,
const Matcher<clang::Expr> ArgumentMatcher) const {
const Matcher<clang::Expr> &ArgumentMatcher) const {
auto HasAnyPrecisionName = hasAnyName(
FunctionName, (FunctionName + "l").str(),
(FunctionName + "f").str()); // Support long double(l) and float(f).
Expand All @@ -100,7 +101,7 @@ struct MatchBuilder {
hasArgument(0, ArgumentMatcher))));
}

auto matchSqrt(const Matcher<clang::Expr> ArgumentMatcher) const {
auto matchSqrt(const Matcher<clang::Expr> &ArgumentMatcher) const {
return matchMathCall("sqrt", ArgumentMatcher);
}

Expand Down Expand Up @@ -148,7 +149,7 @@ struct MatchBuilder {
return expr(anyOf(Int, Float, Dref));
}

auto match1Div(const Matcher<clang::Expr> Match) const {
auto match1Div(const Matcher<clang::Expr> &Match) const {
return binaryOperator(hasOperatorName("/"), hasLHS(matchValue(1)),
hasRHS(Match));
}
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void UseStdPrintCheck::registerPPCallbacks(const SourceManager &SM,
this->PP = PP;
}

static clang::ast_matchers::StatementMatcher
unusedReturnValue(clang::ast_matchers::StatementMatcher MatchedCallExpr) {
static clang::ast_matchers::StatementMatcher unusedReturnValue(
const clang::ast_matchers::StatementMatcher &MatchedCallExpr) {
auto UnusedInCompoundStmt =
compoundStmt(forEach(MatchedCallExpr),
// The checker can't currently differentiate between the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace clang::tidy::portability {
class RestrictSystemIncludesCheck : public ClangTidyCheck {
public:
RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context,
std::string DefaultAllowedIncludes = "*")
StringRef DefaultAllowedIncludes = "*")
: ClangTidyCheck(Name, Context),
AllowedIncludes(Options.get("Includes", DefaultAllowedIncludes)),
AllowedIncludesGlobList(AllowedIncludes) {}
Expand All @@ -36,7 +36,7 @@ class RestrictSystemIncludesCheck : public ClangTidyCheck {
}

private:
std::string AllowedIncludes;
StringRef AllowedIncludes;
GlobList AllowedIncludesGlobList;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
const auto StringNpos = anyOf(declRefExpr(to(varDecl(hasName("npos")))),
memberExpr(member(hasName("npos"))));

auto AddSimpleMatcher = [&](auto Matcher) {
Finder->addMatcher(
traverse(TK_IgnoreUnlessSpelledInSource, std::move(Matcher)), this);
auto AddSimpleMatcher = [&](const auto &Matcher) {
Finder->addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, Matcher), this);
};

// Find membership tests which use `count()`.
Expand Down
7 changes: 3 additions & 4 deletions clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,9 @@ createOptionsProvider(llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS) {
}

static llvm::IntrusiveRefCntPtr<vfs::FileSystem>
getVfsFromFile(const std::string &OverlayFile,
llvm::IntrusiveRefCntPtr<vfs::FileSystem> BaseFS) {
getVfsFromFile(const std::string &OverlayFile, vfs::FileSystem &BaseFS) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question about IntrusiveRefCntPtr -> &

llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
BaseFS->getBufferForFile(OverlayFile);
BaseFS.getBufferForFile(OverlayFile);
if (!Buffer) {
llvm::errs() << "Can't load virtual filesystem overlay file '"
<< OverlayFile << "': " << Buffer.getError().message()
Expand Down Expand Up @@ -583,7 +582,7 @@ static llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> createBaseFS() {

if (!VfsOverlay.empty()) {
IntrusiveRefCntPtr<vfs::FileSystem> VfsFromFile =
getVfsFromFile(VfsOverlay, BaseFS);
getVfsFromFile(VfsOverlay, *BaseFS);
if (!VfsFromFile)
return nullptr;
BaseFS->pushOverlay(std::move(VfsFromFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ BraceInsertionHints getBraceInsertionsHints(const Stmt *const S,

// StartLoc points at the location of the opening brace to be inserted.
SourceLocation EndLoc;
std::string ClosingInsertion;
StringRef ClosingInsertion;
if (EndLocHint.isValid()) {
EndLoc = EndLocHint;
ClosingInsertion = "} ";
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/utils/BracesAroundStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct BraceInsertionHints {
/// Constructor for a hint offering fix-its for brace insertion. Both
/// positions must be valid.
BraceInsertionHints(SourceLocation OpeningBracePos,
SourceLocation ClosingBracePos, std::string ClosingBrace)
SourceLocation ClosingBracePos, StringRef ClosingBrace)
: DiagnosticPos(OpeningBracePos), OpeningBracePos(OpeningBracePos),
ClosingBracePos(ClosingBracePos), ClosingBrace(ClosingBrace) {
assert(offersFixIts());
Expand All @@ -61,7 +61,7 @@ struct BraceInsertionHints {
private:
SourceLocation OpeningBracePos;
SourceLocation ClosingBracePos;
std::string ClosingBrace;
StringRef ClosingBrace;
};

/// Create fix-it hints for braces that wrap the given statement when applied.
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ bool isFunctionPointerConvertible(QualType From, QualType To) {
//
// The function should only be called in C++ mode.
bool isQualificationConvertiblePointer(QualType From, QualType To,
LangOptions LangOpts) {
const LangOptions &LangOpts) {

// [N4659 7.5 (1)]
// A cv-decomposition of a type T is a sequence of cv_i and P_i such that T is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ TransformerClangTidyCheck::TransformerClangTidyCheck(StringRef Name,
// we would be accessing `getLangOpts` and `Options` before the underlying
// `ClangTidyCheck` instance was properly initialized.
TransformerClangTidyCheck::TransformerClangTidyCheck(
std::function<std::optional<RewriteRuleWith<std::string>>(
llvm::function_ref<std::optional<RewriteRuleWith<std::string>>(
const LangOptions &, const OptionsView &)>
MakeRule,
StringRef Name, ClangTidyContext *Context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class TransformerClangTidyCheck : public ClangTidyCheck {
///
/// See \c setRule for constraints on the rule.
TransformerClangTidyCheck(
std::function<std::optional<transformer::RewriteRuleWith<std::string>>(
const LangOptions &, const OptionsView &)>
llvm::function_ref<
std::optional<transformer::RewriteRuleWith<std::string>>(
const LangOptions &, const OptionsView &)>
MakeRule,
StringRef Name, ClangTidyContext *Context);

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ AST_MATCHER(Expr, hasSideEffects) {
} // namespace

static auto
makeExprMatcher(ast_matchers::internal::Matcher<Expr> ArgumentMatcher,
makeExprMatcher(const ast_matchers::internal::Matcher<Expr> &ArgumentMatcher,
ArrayRef<StringRef> MethodNames,
ArrayRef<StringRef> FreeNames) {
return expr(
Expand Down