Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:21

0001 //===--- UnnecessaryValueParamCheck.h - clang-tidy---------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_VALUE_PARAM_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_VALUE_PARAM_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "../utils/IncludeInserter.h"
0014 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
0015 
0016 namespace clang::tidy::performance {
0017 
0018 /// A check that flags value parameters of expensive to copy types that
0019 /// can safely be converted to const references.
0020 ///
0021 /// For the user-facing documentation see:
0022 /// http://clang.llvm.org/extra/clang-tidy/checks/performance/unnecessary-value-param.html
0023 class UnnecessaryValueParamCheck : public ClangTidyCheck {
0024 public:
0025   UnnecessaryValueParamCheck(StringRef Name, ClangTidyContext *Context);
0026   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0027     return LangOpts.CPlusPlus;
0028   }
0029   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0030   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0031   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
0032                            Preprocessor *ModuleExpanderPP) override;
0033   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0034   void onEndOfTranslationUnit() override;
0035 
0036 protected:
0037   // Create diagnostics. These are virtual so that derived classes can change
0038   // behaviour.
0039   virtual void handleMoveFix(const ParmVarDecl &Param,
0040                              const DeclRefExpr &CopyArgument,
0041                              ASTContext &Context);
0042   virtual void handleConstRefFix(const FunctionDecl &Function,
0043                                  const ParmVarDecl &Param, ASTContext &Context);
0044 
0045 private:
0046   ExprMutationAnalyzer::Memoized MutationAnalyzerCache;
0047   utils::IncludeInserter Inserter;
0048   const std::vector<StringRef> AllowedTypes;
0049 };
0050 
0051 } // namespace clang::tidy::performance
0052 
0053 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_VALUE_PARAM_H