[PATCH] D48027: [analyzer] Improve `CallDescription` to handle c++ method.
Henry Wong via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 11 07:56:49 PDT 2018
MTC updated this revision to Diff 150758.
MTC added a comment.
Remove useless header files for testing.
Repository:
rC Clang
https://reviews.llvm.org/D48027
Files:
include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
lib/StaticAnalyzer/Core/CallEvent.cpp
Index: lib/StaticAnalyzer/Core/CallEvent.cpp
===================================================================
--- lib/StaticAnalyzer/Core/CallEvent.cpp
+++ lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -256,11 +256,18 @@
return false;
if (!CD.IsLookupDone) {
CD.IsLookupDone = true;
- CD.II = &getState()->getStateManager().getContext().Idents.get(CD.FuncName);
+ CD.II = &getState()->getStateManager().getContext().Idents.get(
+ CD.getFunctionName());
}
const IdentifierInfo *II = getCalleeIdentifier();
if (!II || II != CD.II)
return false;
+
+ const auto *ND = dyn_cast_or_null<NamedDecl>(getDecl());
+ if (!ND)
+ return false;
+ if (!CD.matchQualifiedName(ND->getQualifiedNameAsString()))
+ return false;
return (CD.RequiredArgs == CallDescription::NoArgRequirement ||
CD.RequiredArgs == getNumArgs());
}
Index: include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
===================================================================
--- include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -79,6 +79,8 @@
mutable IdentifierInfo *II = nullptr;
mutable bool IsLookupDone = false;
+ // Represent the function name or method name, like "c_str" or
+ // "std::string::c_str".
StringRef FuncName;
unsigned RequiredArgs;
@@ -96,7 +98,25 @@
: FuncName(FuncName), RequiredArgs(RequiredArgs) {}
/// Get the name of the function that this object matches.
- StringRef getFunctionName() const { return FuncName; }
+ StringRef getFunctionName() const {
+ auto QualifierNamePair = FuncName.rsplit("::");
+ return QualifierNamePair.second.empty() ? QualifierNamePair.first
+ : QualifierNamePair.second;
+ }
+
+ bool matchQualifiedName(llvm::StringRef QualifiedName) const {
+ llvm::SmallVector<llvm::StringRef, 2> Names;
+ // Split the function name with the separator "::".
+ FuncName.split(Names, "::");
+
+ // FIXME: Since there is no perfect way to get the qualified name without
+ // template argument, we can only use a fuzzy matching approach.
+ for (auto item : Names)
+ if (QualifiedName.find(item) == StringRef::npos)
+ return false;
+
+ return true;
+ }
};
template<typename T = CallEvent>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48027.150758.patch
Type: text/x-patch
Size: 2352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180611/41cbf35e/attachment.bin>
More information about the cfe-commits
mailing list