[clang] [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto keyword (PR #86808)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 27 08:10:11 PDT 2024
https://github.com/smanna12 updated https://github.com/llvm/llvm-project/pull/86808
>From 64ee510df037daeccb98a3fd9fa7e2ac5c41d279 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Wed, 27 Mar 2024 07:41:09 -0700
Subject: [PATCH 1/2] [NFC][CLANG] Fix static analyzer bugs about unnecessary
object copies with auto keyword
Reported by Static Analyzer Tool:
In clang::installapi::InstallAPIVisitor::VisitFunctionDecl(clang::FunctionDecl const *): Using the auto keyword without an & causes the copy of an object of type DynTypedNode.
---
clang/lib/InstallAPI/Visitor.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/InstallAPI/Visitor.cpp b/clang/lib/InstallAPI/Visitor.cpp
index f8f5d8d53d5691..43878463caccbb 100644
--- a/clang/lib/InstallAPI/Visitor.cpp
+++ b/clang/lib/InstallAPI/Visitor.cpp
@@ -255,7 +255,7 @@ bool InstallAPIVisitor::VisitFunctionDecl(const FunctionDecl *D) {
return true;
// Skip methods in CXX RecordDecls.
- for (auto P : D->getASTContext().getParents(*M)) {
+ for (const auto &P : D->getASTContext().getParents(*M)) {
if (P.get<CXXRecordDecl>())
return true;
}
>From e5f65be5b5330007d827f9850a4c41cecab9485a Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Wed, 27 Mar 2024 08:09:11 -0700
Subject: [PATCH 2/2] Address review comment
---
clang/lib/InstallAPI/Visitor.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/InstallAPI/Visitor.cpp b/clang/lib/InstallAPI/Visitor.cpp
index 43878463caccbb..6476c5107cb5cc 100644
--- a/clang/lib/InstallAPI/Visitor.cpp
+++ b/clang/lib/InstallAPI/Visitor.cpp
@@ -255,7 +255,7 @@ bool InstallAPIVisitor::VisitFunctionDecl(const FunctionDecl *D) {
return true;
// Skip methods in CXX RecordDecls.
- for (const auto &P : D->getASTContext().getParents(*M)) {
+ for (const DynTypedNode &P : D->getASTContext().getParents(*M)) {
if (P.get<CXXRecordDecl>())
return true;
}
More information about the cfe-commits
mailing list