<div dir="ltr">Thanks!<div><br></div><div>If it takes a few hours to investigate, I think it's better to revert first and then investigate while the tree is green.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 30, 2019 at 4:43 PM Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_-8110649721709630473WordSection1">
<p class="MsoNormal">Should be fixe din r373259<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><a name="m_-8110649721709630473______replyseparator"></a><b>From:</b> Nico Weber <<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>>
<br>
<b>Sent:</b> Monday, September 30, 2019 12:50 PM<br>
<b>To:</b> Keane, Erich <<a href="mailto:erich.keane@intel.com" target="_blank">erich.keane@intel.com</a>><br>
<b>Cc:</b> cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
<b>Subject:</b> Re: r373247 - Teach CallGraph to look into Generic Lambdas.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">This broke a few clangd unit tests:<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/38857/steps/ninja%20check%201/logs/FAIL%3A%20Clangd%20Unit%20Tests%3A%3AHover.Structured" target="_blank">http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/38857/steps/ninja%20check%201/logs/FAIL%3A%20Clangd%20Unit%20Tests%3A%3AHover.Structured</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/38857/steps/ninja%20check%201/logs/FAIL%3A%20Clangd%20Unit%20Tests%3A%3AHover.All" target="_blank">http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/38857/steps/ninja%20check%201/logs/FAIL%3A%20Clangd%20Unit%20Tests%3A%3AHover.All</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="http://45.33.8.238/linux/680/step_7.txt" target="_blank">http://45.33.8.238/linux/680/step_7.txt</a><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Mon, Sep 30, 2019 at 3:10 PM Erich Keane via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Author: erichkeane<br>
Date: Mon Sep 30 12:12:29 2019<br>
New Revision: 373247<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=373247&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=373247&view=rev</a><br>
Log:<br>
Teach CallGraph to look into Generic Lambdas.<br>
<br>
CallGraph visited LambdaExpr by getting the Call Operator from<br>
CXXRecordDecl (LambdaExpr::getCallOperator calls<br>
CXXRecordDecl::getLambdaCallOperator), which replaced generic lambda<br>
call operators with the non-instantiated FunctionDecl.  The result was<br>
that the CallGraph would only pick up non-dependent calls.<br>
<br>
This patch does a few things:<br>
1- Extend CXXRecordDecl to have a getDependentLambdaCallOperator, which<br>
will get the FunctionTemplateDecl, rather than immediately getting the<br>
TemplateDecl.<br>
2- Define getLambdaCallOperator and getDependentLambdaCallOperator in<br>
terms of a common function.<br>
3- Extend LambdaExpr with a getDependentCallOperator, which just calls<br>
the above function.<br>
4- Changes CallGraph to handle Generic LambdaExprs.<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/AST/DeclCXX.h<br>
    cfe/trunk/include/clang/AST/ExprCXX.h<br>
    cfe/trunk/lib/AST/DeclCXX.cpp<br>
    cfe/trunk/lib/AST/ExprCXX.cpp<br>
    cfe/trunk/lib/Analysis/CallGraph.cpp<br>
    cfe/trunk/test/Analysis/debug-CallGraph.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/DeclCXX.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=373247&r1=373246&r2=373247&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=373247&r1=373246&r2=373247&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)<br>
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Sep 30 12:12:29 2019<br>
@@ -1172,6 +1172,10 @@ public:<br>
   /// if this is a closure type.<br>
   CXXMethodDecl *getLambdaCallOperator() const;<br>
<br>
+  /// Retrieve the dependent lambda call operator of the closure type<br>
+  /// if this is a templated closure type.<br>
+  FunctionTemplateDecl *getDependentLambdaCallOperator() const;<br>
+<br>
   /// Retrieve the lambda static invoker, the address of which<br>
   /// is returned by the conversion operator, and the body of which<br>
   /// is forwarded to the lambda call operator.<br>
<br>
Modified: cfe/trunk/include/clang/AST/ExprCXX.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=373247&r1=373246&r2=373247&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=373247&r1=373246&r2=373247&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)<br>
+++ cfe/trunk/include/clang/AST/ExprCXX.h Mon Sep 30 12:12:29 2019<br>
@@ -1907,6 +1907,10 @@ public:<br>
   /// lambda expression.<br>
   CXXMethodDecl *getCallOperator() const;<br>
<br>
+  /// Retrieve the function template call operator associated with this<br>
+  /// lambda expression.<br>
+  FunctionTemplateDecl *getDependentCallOperator() const;<br>
+<br>
   /// If this is a generic lambda expression, retrieve the template<br>
   /// parameter list associated with it, or else return null.<br>
   TemplateParameterList *getTemplateParameterList() const;<br>
<br>
Modified: cfe/trunk/lib/AST/DeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=373247&r1=373246&r2=373247&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=373247&r1=373246&r2=373247&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/AST/DeclCXX.cpp Mon Sep 30 12:12:29 2019<br>
@@ -1399,17 +1399,25 @@ static bool allLookupResultsAreTheSame(c<br>
 }<br>
 #endif<br>
<br>
-CXXMethodDecl* CXXRecordDecl::getLambdaCallOperator() const {<br>
-  if (!isLambda()) return nullptr;<br>
+NamedDecl* getLambdaCallOperatorHelper(const CXXRecordDecl &RD) {<br>
+  if (!RD.isLambda()) return nullptr;<br>
   DeclarationName Name =<br>
-    getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);<br>
-  DeclContext::lookup_result Calls = lookup(Name);<br>
+    RD.getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);<br>
+  DeclContext::lookup_result Calls = RD.lookup(Name);<br>
<br>
   assert(!Calls.empty() && "Missing lambda call operator!");<br>
   assert(allLookupResultsAreTheSame(Calls) &&<br>
          "More than one lambda call operator!");<br>
+  return Calls.front();<br>
+}<br>
+<br>
+FunctionTemplateDecl* CXXRecordDecl::getDependentLambdaCallOperator() const {<br>
+  NamedDecl *CallOp = getLambdaCallOperatorHelper(*this);<br>
+  return  dyn_cast<FunctionTemplateDecl>(CallOp);<br>
+}<br>
<br>
-  NamedDecl *CallOp = Calls.front();<br>
+CXXMethodDecl *CXXRecordDecl::getLambdaCallOperator() const {<br>
+  NamedDecl *CallOp = getLambdaCallOperatorHelper(*this);<br>
   if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp))<br>
     return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl());<br>
<br>
<br>
Modified: cfe/trunk/lib/AST/ExprCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=373247&r1=373246&r2=373247&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=373247&r1=373246&r2=373247&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)<br>
+++ cfe/trunk/lib/AST/ExprCXX.cpp Mon Sep 30 12:12:29 2019<br>
@@ -1218,6 +1218,11 @@ CXXMethodDecl *LambdaExpr::getCallOperat<br>
   return Record->getLambdaCallOperator();<br>
 }<br>
<br>
+FunctionTemplateDecl *LambdaExpr::getDependentCallOperator() const {<br>
+  CXXRecordDecl *Record = getLambdaClass();<br>
+  return Record->getDependentLambdaCallOperator();<br>
+}<br>
+<br>
 TemplateParameterList *LambdaExpr::getTemplateParameterList() const {<br>
   CXXRecordDecl *Record = getLambdaClass();<br>
   return Record->getGenericLambdaTemplateParameterList();<br>
<br>
Modified: cfe/trunk/lib/Analysis/CallGraph.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CallGraph.cpp?rev=373247&r1=373246&r2=373247&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CallGraph.cpp?rev=373247&r1=373246&r2=373247&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Analysis/CallGraph.cpp (original)<br>
+++ cfe/trunk/lib/Analysis/CallGraph.cpp Mon Sep 30 12:12:29 2019<br>
@@ -80,7 +80,10 @@ public:<br>
   }<br>
<br>
   void VisitLambdaExpr(LambdaExpr *LE) {<br>
-    if (CXXMethodDecl *MD = LE->getCallOperator())<br>
+    if (FunctionTemplateDecl *FTD = LE->getDependentCallOperator())<br>
+      for (FunctionDecl *FD : FTD->specializations())<br>
+        G->VisitFunctionDecl(FD);<br>
+    else if (CXXMethodDecl *MD = LE->getCallOperator())<br>
       G->VisitFunctionDecl(MD);<br>
   }<br>
<br>
<br>
Modified: cfe/trunk/test/Analysis/debug-CallGraph.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/debug-CallGraph.cpp?rev=373247&r1=373246&r2=373247&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/debug-CallGraph.cpp?rev=373247&r1=373246&r2=373247&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Analysis/debug-CallGraph.cpp (original)<br>
+++ cfe/trunk/test/Analysis/debug-CallGraph.cpp Mon Sep 30 12:12:29 2019<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCallGraph %s -fblocks 2>&1 | FileCheck %s<br>
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCallGraph %s -fblocks -std=c++14 2>&1 | FileCheck %s<br>
<br>
 int get5() {<br>
   return 5;<br>
@@ -68,8 +68,25 @@ void templUser() {<br>
 }<br>
 }<br>
<br>
+namespace Lambdas {<br>
+  void Callee(){}<br>
+<br>
+  void f1() {<br>
+    [](int i) {<br>
+      Callee();<br>
+    }(1);<br>
+    [](auto i) {<br>
+      Callee();<br>
+    }(1);<br>
+  }<br>
+}<br>
+<br>
 // CHECK:--- Call graph Dump ---<br>
-// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ SomeNS::templUser $}}<br>
+// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(anonymous class\)::operator\(\) Lambdas::f1\(\)::\(anonymous
 class\)::operator\(\) $}}<br>
+// CHECK-NEXT: {{Function: Lambdas::f1 calls: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) $}}<br>
+// CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) calls: Lambdas::Callee $}}<br>
+// CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) calls: Lambdas::Callee $}}<br>
+// CHECK-NEXT: {{Function: Lambdas::Callee calls: $}}<br>
 // CHECK-NEXT: {{Function: SomeNS::templUser calls: SomeNS::templ SomeNS::templ $}}<br>
 // CHECK-NEXT: {{Function: SomeNS::templ calls: eee $}}<br>
 // CHECK-NEXT: {{Function: SomeNS::templ calls: ccc $}}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>

</blockquote></div>