[PATCH] D65453: Improve the accuracy of the Clang call graph analysis

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 15 15:02:46 PDT 2019

NoQ added a comment.

Thanks! This looks very useful.

Comment at: clang/lib/Analysis/CallGraph.cpp:97-102
+    const auto *ConstructedType = Ctor->getParent();
+    if (ConstructedType->hasUserDeclaredDestructor()) {
+      CXXDestructorDecl *Dtor = ConstructedType->getDestructor();
+      if (FunctionDecl *Def = Dtor->getDefinition())
+        addCalledDecl(Def);
+    }
Ugh this is questionable. The object may easily outlive the function, so the destructor may be called from another function. I see where this was supposed to go (i.e., this is perfectly correct when the constructor is constructing a non-RVO'd temporary or a non-NRVO'd local variable), but in the general case it's not true.

The really nice way to implement this functionality would be to rely on the constructor's `ConstructionContext`, but as of now it's only available in the CFG and there's no easy way to retrieve it by looking at the AST node (and if you have a CFG you might as well look at destructors directly, as they're listed there explicitly).

It should also be possible to do that by hand by matching `DeclStmt`s and `CXXBindTemporaryExpr`s.

Let's omit this part for now because currently the analysis seems to be conservative in the sense that it doesn't add calls when it's not sure.



More information about the cfe-commits mailing list