[PATCH] D48027: [analyzer] Improve `CallDescription` to handle c++ method.

Henry Wong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 4 07:15:24 PDT 2018


MTC added a comment.

Thanks for your review, NoQ!



================
Comment at: lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp:68
     : IILockGuard(nullptr), IIUniqueLock(nullptr),
-      LockFn("lock"), UnlockFn("unlock"), SleepFn("sleep"), GetcFn("getc"),
-      FgetsFn("fgets"), ReadFn("read"), RecvFn("recv"),
-      PthreadLockFn("pthread_mutex_lock"),
-      PthreadTryLockFn("pthread_mutex_trylock"),
-      PthreadUnlockFn("pthread_mutex_unlock"),
-      MtxLock("mtx_lock"),
-      MtxTimedLock("mtx_timedlock"),
-      MtxTryLock("mtx_trylock"),
-      MtxUnlock("mtx_unlock"),
+      LockFn({"lock"}), UnlockFn({"unlock"}), SleepFn({"sleep"}), GetcFn({"getc"}),
+      FgetsFn({"fgets"}), ReadFn({"read"}), RecvFn({"recv"}),
----------------
NoQ wrote:
> I wish the old syntax for simple C functions was preserved.
> 
> This could be accidentally achieved by using `ArrayRef<StringRef>` instead of `std::vector<StringRef>` for your constructor's argument.
`ArrayRef<StringRef>` can't achieve this goal. The only way I can figure out is changing the declaration to the following form.

`CallDescription(StringRef FuncName, unsigned RequiredArgs = NoArgRequirement, ArrayRef<StringRef> QualifiedName = None) {}`


================
Comment at: lib/StaticAnalyzer/Core/CallEvent.cpp:273-280
+    std::string Regex = "^::(.*)?";
+    Regex += llvm::join(CD.QualifiedName, "(.*)?::(.*)?") + "(.*)?$";
+
+    auto Matches = match(namedDecl(matchesName(Regex)).bind("Regex"), *ND,
+                         LCtx->getAnalysisDeclContext()->getASTContext());
+
+    if (Matches.empty())
----------------
NoQ wrote:
> Uhm, i think we don't need to flatten the class name to a string and then regex to do this.
> 
> We can just unwrap the declaration and see if the newly unwrapped layer matches the expected name on every step, until all expected names have been found.
Is the way you mentioned above is similar `NamedDecl::printQualifiedName()`? Get the full name through the `DeclContext` chain. See https://github.com/llvm-mirror/clang/blob/master/lib/AST/Decl.cpp#L1511.

Or ignore namespace ,like `std`, just only consider the `CXXRecordDecl`? If so, `dyn_cast<>` might be enough.


Repository:
  rC Clang

https://reviews.llvm.org/D48027





More information about the cfe-commits mailing list