<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Yep, I agree.  I tend to figure if I can get it done in ~1-2 hours, that I could just fix it.  Note that this was 1:30
<span style="font-family:"Segoe UI Emoji",sans-serif">😊</span> <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><a name="_____replyseparator"></a><b>From:</b> Nico Weber <thakis@chromium.org>
<br>
<b>Sent:</b> Wednesday, October 2, 2019 4:37 PM<br>
<b>To:</b> Keane, Erich <erich.keane@intel.com><br>
<b>Cc:</b> cfe-commits <cfe-commits@lists.llvm.org><br>
<b>Subject:</b> Re: r373247 - Teach CallGraph to look into Generic Lambdas.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Thanks!<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">If it takes a few hours to investigate, I think it's better to revert first and then investigate while the tree is green.<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Mon, Sep 30, 2019 at 4:43 PM Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Should be fixe din r373259<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><a name="m_-8110649721709630473______replyseparat"></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.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">This broke a few clangd unit tests:<o:p></o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><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><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><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><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><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><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</body>
</html>