-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Conversation
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
@llvm/pr-subscribers-clang-analysis @llvm/pr-subscribers-clang Author: None (smanna12) ChangesReported by Static Analyzer tool:
Full diff: https://github.com/llvm/llvm-project/pull/75060.diff 2 Files Affected:
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();
|
Could you also update the description of the patch? |
Done. Thank you @Xazax-hun for reviews! |
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. |
Thank you for reviews everyone! |
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