[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

Eugene Zelenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 1 22:15:43 PDT 2022


Eugene.Zelenko added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:1
+//===--- UnnecessaryCopyOnLastUseCheck.cpp -
+// clang-tidy-----------------------===//
----------------
Please make single line.


================
Comment at: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:228
+  //     Result.Nodes.getNodeAs<CXXConstructExpr>("constructExpr");
+  const auto *const DeclOfParam = Param->getDecl();
+  const auto *const FunctionOfDeclContext =
----------------
Please don't use auto unless type is explicitly spelled in same statement or iterator.


================
Comment at: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:229
+  const auto *const DeclOfParam = Param->getDecl();
+  const auto *const FunctionOfDeclContext =
+      DeclOfParam->getParentFunctionOrMethod();
----------------
Ditto.


================
Comment at: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:257
+
+  auto DefiniteLastUse = definiteLastUse(
+      Result.Context, getOrCreateCFG(FunctionOfDecl, Result.Context), Param);
----------------
Ditto.


================
Comment at: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:273
+
+  auto &&SM = *Result.SourceManager;
+  auto EndLoc = Lexer::getLocForEndOfToken(Param->getLocation(), 0, SM,
----------------
Ditto.


================
Comment at: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:274
+  auto &&SM = *Result.SourceManager;
+  auto EndLoc = Lexer::getLocForEndOfToken(Param->getLocation(), 0, SM,
+                                           Result.Context->getLangOpts());
----------------
Ditto.


================
Comment at: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:335
+} // namespace clang::tidy::performance
\ No newline at end of file

----------------
Please fix.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst:6
+
+Finds variables of non-trivially-copyable types, that are used in a copy construction on their last usage and suggest to wrap the usage in a `std::move`.
+The usage just before an assignment is interpreted as last usage.  
----------------
Please synchronize with Release Notes, follow 80 characters limit and use double back-ticks for language constructs.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst:9
+
+Many programmers tend to forget `std::move` for variables that can be moved. 
+Instead, the compiler creates implicit copies, which can significantly decrease performance.
----------------
Double back-ticks.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst:12
+
+
+Example:
----------------
Excessive newline.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137205/new/

https://reviews.llvm.org/D137205



More information about the cfe-commits mailing list