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.


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

Reply via email to