[clang] [NFC][CLANG] Fix static analyzer bugs about large copy by values (PR #75060)

via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 11 07:33:44 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (smanna12)

<details>
<summary>Changes</summary>

Reported by Static Analyzer tool:

1. In getSourceRangeToTokenEnd(clang::Decl const *, clang::SourceManager const &, clang::LangOptions): A very large function call parameter exceeding the high threshold is passed by value

   pass_by_value: Passing parameter LangOpts of type clang::LangOptions (size 1784 bytes) by value, which exceeds the high threshold of 512 bytes

2. In makeCommonInvocationForModuleBuild(clang::CompilerInvocation): A large function call parameter exceeding the low threshold is passed by value.

   pass_by_value: Passing parameter CI of type clang::CompilerInvocation (size 176 bytes) by value, which exceeds the low threshold of 128 bytes

---
Full diff: https://github.com/llvm/llvm-project/pull/75060.diff


2 Files Affected:

- (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+1-1) 
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+1-1) 


``````````diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index e332a3609290aa..bc23c83f77aea2 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1488,7 +1488,7 @@ static bool hasUnsupportedSpecifiers(const VarDecl *VD,
 // returned by this function is the last location of the last token.
 static SourceRange getSourceRangeToTokenEnd(const Decl *D,
                                             const SourceManager &SM,
-                                            LangOptions LangOpts) {
+                                            const LangOptions &LangOpts) {
   SourceLocation Begin = D->getBeginLoc();
   SourceLocation
     End = // `D->getEndLoc` should always return the starting location of the
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index f65da413bb87c3..598486932563d0 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -110,7 +110,7 @@ void ModuleDepCollector::addOutputPaths(CowCompilerInvocation &CI,
 }
 
 static CowCompilerInvocation
-makeCommonInvocationForModuleBuild(CompilerInvocation CI) {
+makeCommonInvocationForModuleBuild(const CompilerInvocation &CI) {
   CI.resetNonModularOptions();
   CI.clearImplicitModuleBuildOptions();
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/75060


More information about the cfe-commits mailing list