[PATCH] D149631: [NFC][CLANG] Fix static analyzer codes concerns about large copies by value
Soumi Manna via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 1 20:17:24 PDT 2023
Manna created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
Herald added a reviewer: aaron.ballman.
Herald added projects: All, clang, clang-format.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
Manna requested review of this revision.
Reported by Static Analyzer Tool:
1. 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 800 bytes) by value, which exceeds the high threshold of 512 bytes
This patch removes redundant capturing variable S and uses type clang::format::FormatStyle Expanded instead.
2. Inside "ClangAttrEmitter.cpp" file, in clang::GenerateMutualExclusionsChecks(llvm::Record const &, llvm::RecordKeeper const &, llvm::raw_ostream &, llvm::raw_ostream &, llvm::raw_ostream &)::[lambda(llvm::Record const *) (instance 1)]::operator ()(llvm::Record const *): A large function call parameter exceeding the low threshold is passed by value.
pass_by_value: Capturing variable Attr of type llvm::Record const (size 176 bytes) by value, which exceeds the low threshold of 128 bytes.
This patch passes const Record by reference in IsCurAttr lambda capture.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149631
Files:
clang/lib/Format/Format.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===================================================================
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3954,7 +3954,7 @@
for (const Record *Exclusion : ExclusionsList) {
std::vector<Record *> MutuallyExclusiveAttrs =
Exclusion->getValueAsListOfDefs("Exclusions");
- auto IsCurAttr = [Attr](const Record *R) {
+ auto IsCurAttr = [&Attr](const Record *R) {
return R->getName() == Attr.getName();
};
if (llvm::any_of(MutuallyExclusiveAttrs, IsCurAttr)) {
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3483,26 +3483,23 @@
}
if (Style.InsertBraces) {
- FormatStyle S = Expanded;
- S.InsertBraces = true;
- Passes.emplace_back([&, S](const Environment &Env) {
- return BracesInserter(Env, S).process(/*SkipAnnotation=*/true);
+ Expanded.InsertBraces = true;
+ Passes.emplace_back([&](const Environment &Env) {
+ return BracesInserter(Env, Expanded).process(/*SkipAnnotation=*/true);
});
}
if (Style.RemoveBracesLLVM) {
- FormatStyle S = Expanded;
- S.RemoveBracesLLVM = true;
- Passes.emplace_back([&, S](const Environment &Env) {
- return BracesRemover(Env, S).process(/*SkipAnnotation=*/true);
+ Expanded.RemoveBracesLLVM = true;
+ Passes.emplace_back([&](const Environment &Env) {
+ return BracesRemover(Env, Expanded).process(/*SkipAnnotation=*/true);
});
}
if (Style.RemoveSemicolon) {
- FormatStyle S = Expanded;
- S.RemoveSemicolon = true;
- Passes.emplace_back([&, S](const Environment &Env) {
- return SemiRemover(Env, S).process(/*SkipAnnotation=*/true);
+ Expanded.RemoveSemicolon = true;
+ Passes.emplace_back([&](const Environment &Env) {
+ return SemiRemover(Env, Expanded).process(/*SkipAnnotation=*/true);
});
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149631.518627.patch
Type: text/x-patch
Size: 2078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230502/95ca3574/attachment.bin>
More information about the cfe-commits
mailing list