Skip to content

Commit 0d786b9

Browse files
authored
[clang-tidy][NFC] Enable performance-unnecessary-value-param in the codebase (llvm#163686)
Closes llvm#156156. In a few cases, instead of just applying the fix-it and making parameters const references to owning type, I refactored them to be non-owning types.
1 parent 4d88bb6 commit 0d786b9

26 files changed

+59
-58
lines changed

clang-tools-extra/clang-tidy/.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Checks: >
1515
performance-*,
1616
-performance-enum-size,
1717
-performance-no-int-to-ptr,
18-
-performance-unnecessary-value-param,
1918
readability-*,
2019
-readability-avoid-nested-conditional-operator,
2120
-readability-braces-around-statements,

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ ClangTidyASTConsumerFactory::createASTConsumer(
455455

456456
if (Context.canEnableModuleHeadersParsing() &&
457457
Context.getLangOpts().Modules && OverlayFS != nullptr) {
458-
auto ModuleExpander =
459-
std::make_unique<ExpandModularHeadersPPCallbacks>(&Compiler, OverlayFS);
458+
auto ModuleExpander = std::make_unique<ExpandModularHeadersPPCallbacks>(
459+
&Compiler, *OverlayFS);
460460
ModuleExpanderPP = ModuleExpander->getPreprocessor();
461461
PP->addPPCallbacks(std::move(ModuleExpander));
462462
}

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
6565
};
6666

6767
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
68-
CompilerInstance *CI,
69-
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
68+
CompilerInstance *CI, llvm::vfs::OverlayFileSystem &OverlayFS)
7069
: Recorder(std::make_unique<FileRecorder>()), Compiler(*CI),
7170
InMemoryFs(new llvm::vfs::InMemoryFileSystem),
7271
Sources(Compiler.getSourceManager()),
@@ -76,7 +75,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
7675
LangOpts(Compiler.getLangOpts()), HSOpts(Compiler.getHeaderSearchOpts()) {
7776
// Add a FileSystem containing the extra files needed in place of modular
7877
// headers.
79-
OverlayFS->pushOverlay(InMemoryFs);
78+
OverlayFS.pushOverlay(InMemoryFs);
8079

8180
Diags.setSourceManager(&Sources);
8281
// FIXME: Investigate whatever is there better way to initialize DiagEngine

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ namespace tooling {
4141
/// non-modular way.
4242
class ExpandModularHeadersPPCallbacks : public PPCallbacks {
4343
public:
44-
ExpandModularHeadersPPCallbacks(
45-
CompilerInstance *CI,
46-
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS);
44+
ExpandModularHeadersPPCallbacks(CompilerInstance *CI,
45+
llvm::vfs::OverlayFileSystem &OverlayFS);
4746
~ExpandModularHeadersPPCallbacks() override;
4847

4948
/// Returns the preprocessor that provides callbacks for the whole

clang-tools-extra/clang-tidy/android/CloexecCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static std::string buildFixMsgForStringFlag(const Expr *Arg,
3636
}
3737

3838
void CloexecCheck::registerMatchersImpl(
39-
MatchFinder *Finder, internal::Matcher<FunctionDecl> Function) {
39+
MatchFinder *Finder, const internal::Matcher<FunctionDecl> &Function) {
4040
// We assume all the checked APIs are C functions.
4141
Finder->addMatcher(
4242
callExpr(

clang-tools-extra/clang-tidy/android/CloexecCheck.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class CloexecCheck : public ClangTidyCheck {
2929
: ClangTidyCheck(Name, Context) {}
3030

3131
protected:
32-
void
33-
registerMatchersImpl(ast_matchers::MatchFinder *Finder,
34-
ast_matchers::internal::Matcher<FunctionDecl> Function);
32+
void registerMatchersImpl(
33+
ast_matchers::MatchFinder *Finder,
34+
const ast_matchers::internal::Matcher<FunctionDecl> &Function);
3535

3636
/// Currently, we have three types of fixes.
3737
///

clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <initializer_list>
1919
#include <optional>
2020
#include <string>
21+
#include <utility>
2122

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

@@ -217,11 +218,11 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
217218
const auto AddFromStd =
218219
[&](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
219220
std::initializer_list<StringRef> Names) {
220-
AddFrom(Replacer, Names, "std");
221+
AddFrom(std::move(Replacer), Names, "std");
221222
};
222223

223224
const auto AddFromBoost =
224-
[&](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
225+
[&](const llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> &Replacer,
225226
std::initializer_list<
226227
std::pair<StringRef, std::initializer_list<StringRef>>>
227228
NamespaceAndNames) {

clang-tools-extra/clang-tidy/bugprone/RawMemoryCallOnNonTrivialTypeCheck.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ void RawMemoryCallOnNonTrivialTypeCheck::storeOptions(
6464

6565
void RawMemoryCallOnNonTrivialTypeCheck::registerMatchers(MatchFinder *Finder) {
6666
using namespace ast_matchers::internal;
67-
auto IsStructPointer = [](Matcher<CXXRecordDecl> Constraint = anything(),
67+
auto IsStructPointer = [](const Matcher<CXXRecordDecl> &Constraint =
68+
anything(),
6869
bool Bind = false) {
6970
return expr(unaryOperator(
7071
hasOperatorName("&"),
@@ -74,8 +75,8 @@ void RawMemoryCallOnNonTrivialTypeCheck::registerMatchers(MatchFinder *Finder) {
7475
};
7576
auto IsRecordSizeOf =
7677
expr(sizeOfExpr(hasArgumentOfType(equalsBoundNode("Record"))));
77-
auto ArgChecker = [&](Matcher<CXXRecordDecl> RecordConstraint,
78-
BindableMatcher<Stmt> SecondArg = expr()) {
78+
auto ArgChecker = [&](const Matcher<CXXRecordDecl> &RecordConstraint,
79+
const BindableMatcher<Stmt> &SecondArg = expr()) {
7980
return allOf(argumentCountIs(3),
8081
hasArgument(0, IsStructPointer(RecordConstraint, true)),
8182
hasArgument(1, SecondArg), hasArgument(2, IsRecordSizeOf));

clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ void SignalHandlerCheck::check(const MatchFinder::MatchResult &Result) {
435435

436436
bool SignalHandlerCheck::checkFunction(
437437
const FunctionDecl *FD, const Expr *CallOrRef,
438-
std::function<void(bool)> ChainReporter) {
438+
llvm::function_ref<void(bool)> ChainReporter) {
439439
const bool FunctionIsCalled = isa<CallExpr>(CallOrRef);
440440

441441
if (isStandardFunction(FD)) {
@@ -471,7 +471,7 @@ bool SignalHandlerCheck::checkFunction(
471471

472472
bool SignalHandlerCheck::checkFunctionCPP14(
473473
const FunctionDecl *FD, const Expr *CallOrRef,
474-
std::function<void(bool)> ChainReporter) {
474+
llvm::function_ref<void(bool)> ChainReporter) {
475475
if (!FD->isExternC()) {
476476
diag(CallOrRef->getBeginLoc(),
477477
"functions without C linkage are not allowed as signal "

clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class SignalHandlerCheck : public ClangTidyCheck {
4848
/// The bool parameter is used like \c SkipPathEnd in \c reportHandlerChain .
4949
/// \return Returns true if a diagnostic was emitted for this function.
5050
bool checkFunction(const FunctionDecl *FD, const Expr *CallOrRef,
51-
std::function<void(bool)> ChainReporter);
51+
llvm::function_ref<void(bool)> ChainReporter);
5252
/// Similar as \c checkFunction but only check for C++14 rules.
5353
bool checkFunctionCPP14(const FunctionDecl *FD, const Expr *CallOrRef,
54-
std::function<void(bool)> ChainReporter);
54+
llvm::function_ref<void(bool)> ChainReporter);
5555
/// Returns true if a standard library function is considered
5656
/// asynchronous-safe.
5757
bool isStandardFunctionAsyncSafe(const FunctionDecl *FD) const;

0 commit comments

Comments
 (0)