[PATCH] D111535: [analyzer] Allow matching non-CallExprs using CallDescriptions

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 18 05:58:34 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG72d04d7b2b53: [analyzer] Allow matching non-CallExprs using CallDescriptions (authored by steakhal).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111535/new/

https://reviews.llvm.org/D111535

Files:
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp


Index: clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
===================================================================
--- clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
+++ clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
@@ -187,12 +187,11 @@
       using namespace std;
       basic_string<char> s("hello");
     })code";
-  // FIXME: We should match.
   const std::string Code = (Twine{MockStdStringHeader} + AdditionalCode).str();
   EXPECT_TRUE(tooling::runToolOnCode(
       std::unique_ptr<FrontendAction>(
           new CallDescriptionAction<CXXConstructExpr>({
-              {{{"std", "basic_string", "basic_string"}, 2, 2}, false},
+              {{{"std", "basic_string", "basic_string"}, 2, 2}, true},
           })),
       Code));
 }
@@ -216,10 +215,9 @@
       aaa::bbb::Bar x;
       int tmp = x;
     })code";
-  // FIXME: We should match.
   EXPECT_TRUE(tooling::runToolOnCode(
       std::unique_ptr<FrontendAction>(new CallDescriptionAction<>({
-          {{{"aaa", "bbb", "Bar", "operator int"}}, false},
+          {{{"aaa", "bbb", "Bar", "operator int"}}, true},
       })),
       Code));
 }
Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -328,9 +328,11 @@
     if (const auto *II = Name.getAsIdentifierInfo())
       return II == CD.II.getValue(); // Fast case.
 
-    // Simply report mismatch for:
+    // Fallback to the slow stringification and comparison for:
     // C++ overloaded operators, constructors, destructors, etc.
-    return false;
+    // FIXME This comparison is way SLOWER than comparing pointers.
+    // At some point in the future, we should compare FunctionDecl pointers.
+    return Name.getAsString() == CD.getFunctionName();
   };
 
   const auto ExactMatchArgAndParamCounts =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111535.380363.patch
Type: text/x-patch
Size: 1929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211018/cc9176a3/attachment.bin>


More information about the cfe-commits mailing list