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>


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>
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to