[clang] babe862 - [NFC][Clang] Fix static analyzer tool remarks about large copies by values in Format.cpp file

via cfe-commits cfe-commits at lists.llvm.org
Fri May 5 18:58:36 PDT 2023


Author: Manna, Soumi
Date: 2023-05-05T18:55:49-07:00
New Revision: babe8629d73fb52bf85516222cd484da0eed6c12

URL: https://github.com/llvm/llvm-project/commit/babe8629d73fb52bf85516222cd484da0eed6c12
DIFF: https://github.com/llvm/llvm-project/commit/babe8629d73fb52bf85516222cd484da0eed6c12.diff

LOG: [NFC][Clang] Fix static analyzer tool remarks about large copies by values in Format.cpp file

Reported by Static Analyzer Tool, Coverity:

Inside "Format.cpp" file, in clang::format::internal::reformat(clang::format::FormatStyle const &, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned int, unsigned int, llvm::StringRef, clang::format::FormattingAttemptStatus *)::[lambda(clang::format::Environment const &) (instance 4)]::operator ()(clang::format::Environment const &): A very large function call parameter exceeding the high threshold is passed by value.

pass_by_value: Capturing variable S of type clang::format::FormatStyle (size 808 bytes) by value, which exceeds the high threshold of 512 bytes

This patch uses original code but with an init capture that does a move instead of a copy.

Reviewed By: tahonermann, erichkeane, MyDeveloperDay, owenpan, HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D149647

Added: 
    

Modified: 
    clang/lib/Format/Format.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index f7c82c581bfc9..ae3f822a2b323 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3485,7 +3485,7 @@ reformat(const FormatStyle &Style, StringRef Code,
     if (Style.InsertBraces) {
       FormatStyle S = Expanded;
       S.InsertBraces = true;
-      Passes.emplace_back([&, S](const Environment &Env) {
+      Passes.emplace_back([&, S = std::move(S)](const Environment &Env) {
         return BracesInserter(Env, S).process(/*SkipAnnotation=*/true);
       });
     }
@@ -3493,7 +3493,7 @@ reformat(const FormatStyle &Style, StringRef Code,
     if (Style.RemoveBracesLLVM) {
       FormatStyle S = Expanded;
       S.RemoveBracesLLVM = true;
-      Passes.emplace_back([&, S](const Environment &Env) {
+      Passes.emplace_back([&, S = std::move(S)](const Environment &Env) {
         return BracesRemover(Env, S).process(/*SkipAnnotation=*/true);
       });
     }
@@ -3501,7 +3501,7 @@ reformat(const FormatStyle &Style, StringRef Code,
     if (Style.RemoveSemicolon) {
       FormatStyle S = Expanded;
       S.RemoveSemicolon = true;
-      Passes.emplace_back([&, S](const Environment &Env) {
+      Passes.emplace_back([&, S = std::move(S)](const Environment &Env) {
         return SemiRemover(Env, S).process(/*SkipAnnotation=*/true);
       });
     }


        


More information about the cfe-commits mailing list