Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC][CLANG] Fix static analyzer bugs about large copy by values #75060

Merged
merged 2 commits into from
Dec 12, 2023

Conversation

smanna12
Copy link
Contributor

@smanna12 smanna12 commented Dec 11, 2023

Reported by Static Analyzer tool:

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

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
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:analysis labels Dec 11, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 11, 2023

@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: None (smanna12)

Changes

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 --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();
 

@Xazax-hun
Copy link
Collaborator

Could you also update the description of the patch?

@smanna12
Copy link
Contributor Author

Could you also update the description of the patch?

Done. Thank you @Xazax-hun for reviews!

@haoNoQ
Copy link
Collaborator

haoNoQ commented Dec 11, 2023

Thanks for catching these!

I wonder what would it take to delete the copy constructors on these classes, so that these mistakes are never made again.

@smanna12 smanna12 merged commit a9b3054 into llvm:main Dec 12, 2023
4 checks passed
@smanna12
Copy link
Contributor Author

Thank you for reviews everyone!

@smanna12 smanna12 deleted the Fix_NullBugs branch December 12, 2023 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:analysis clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants