[PATCH] D29183: [Analysis] Fix for call graph to correctly handle nested call expressions

Balogh, Ádám via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 26 08:51:05 PST 2017


baloghadamsoftware created this revision.

Take the following example:

  class Int {
  public:
    Int(int n = 0): num(n) {}
    Int(const Int& rhs): num(rhs.num) {}
    Int& operator=(const Int& rhs) { num = rhs.num; }
    operator int() { return num; }
  private:
    int num;
  };
  
  
  template<typename T>
  T h(T n) {
    return n;
  }
  
  Int f(Int n) {
    Int i;
    i = h(n);
    return i;
  }
  
  Int g(Int n) {
    Int i = h(n);
    return i;
  }

The call graph for this C++ compilation unit will omit the edge from f to h, but not from g to h. This is obviously an error. The reason is that when visiting the statements to build the call graph all call expressions are handled as leafs. In the example above f calls operator=, which is a call expression, but it also has a child call expression, a call to function h. However, this latter edge is not visited because operator= is handled as leaf and its child call expression is not visited.


https://reviews.llvm.org/D29183

Files:
  lib/Analysis/CallGraph.cpp


Index: lib/Analysis/CallGraph.cpp
===================================================================
--- lib/Analysis/CallGraph.cpp
+++ lib/Analysis/CallGraph.cpp
@@ -62,6 +62,7 @@
   void VisitCallExpr(CallExpr *CE) {
     if (Decl *D = getDeclFromCall(CE))
       addCalledDecl(D);
+    VisitChildren(CE);
   }
 
   // Adds may-call edges for the ObjC message sends.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29183.85920.patch
Type: text/x-patch
Size: 370 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170126/5f39e67b/attachment.bin>


More information about the cfe-commits mailing list