diff options
author | Alexander Kornienko <alexfh@google.com> | 2015-12-30 10:24:40 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2015-12-30 10:24:40 +0000 |
commit | b959f4c33882b1f5150bb54a1664befad4251af8 (patch) | |
tree | 62369d8b12b8d3c3cc8e91e29816205cc8099d2b /clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp | |
parent | 779c66f3ca9e51efd0b8eaac75347df4b109c7d2 (diff) | |
download | bcm5719-llvm-b959f4c33882b1f5150bb54a1664befad4251af8.tar.gz bcm5719-llvm-b959f4c33882b1f5150bb54a1664befad4251af8.zip |
[clang-tidy] Add UnnecessaryCopyInitialization check to new "performance" module in ClangTidy
Summary:
The patch adds a new ClangTidy check that detects when expensive-to-copy types are unnecessarily copy initialized from a const reference that has the same or are larger scope than the copy.
It currently only detects this when the copied variable is const qualified. But this will be extended to non const variables if they are only used in a const fashion.
Reviewers: alexfh
Subscribers: cfe-commits
Patch by Felix Berger!
Differential Revision: http://reviews.llvm.org/D15623
llvm-svn: 256632
Diffstat (limited to 'clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp new file mode 100644 index 00000000000..ab0dbc8012a --- /dev/null +++ b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp @@ -0,0 +1,39 @@ +//===--- PeformanceTidyModule.cpp - clang-tidy ----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "../ClangTidy.h" +#include "../ClangTidyModule.h" +#include "../ClangTidyModuleRegistry.h" + +#include "UnnecessaryCopyInitialization.h" + +namespace clang { +namespace tidy { +namespace performance { + +class PerformanceModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck<UnnecessaryCopyInitialization>( + "performance-unnecessary-copy-initialization"); + } +}; + +// Register the PerformanceModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add<PerformanceModule> + X("performance-module", "Adds performance checks."); + +} // namespace performance + +// This anchor is used to force the linker to link in the generated object file +// and thus register the PerformanceModule. +volatile int PerformanceModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang |