<div dir="ltr">The patch'll need a test case (in clang/tests) - I've not looked at the change/have much opinion there, just suggesting adding a test at minimum so when someone does come to review it it's more complete/closer to/ready to commit.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 17, 2016 at 9:23 PM, Taewook Oh via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">twoh created this revision.<br>
twoh added reviewers: faisalv, rsmith.<br>
twoh added a subscriber: cfe-commits.<br>
<br>
(This is a fix for Bug 27797 <a href="https://llvm.org/bugs/show_bug.cgi?id=27797" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=27797</a>).<br>
<br>
Currently when RebuildLambdaScopeInfo() function in lib/Sema/SemaDecl.cpp observes lambda capturing 'this', it calls Sema::getCurrentThisType() to get the type of 'this'. However, clang (revision 269789) crashes with an assertion failure inside Sema::getCurrentThisType() if template instantiation creates nested lambdas. Inside, Sema::getCurrentThisType(), there is an assertion saying that getCurLambda() never returns nullptr, but nest lambdas created by template instantiation makes getCurLambda() returns nullptr.<br>
<br>
Actually, even without the assertion failure, calling Sema::getCurrentThisType() from RebuildLambdaScopeInfo() seems wrong. When there are nested lambdas, what is required from Sema::getCurrentThisType() is a type of 'this' for nesting lambda, while what is supposed to be returned from Sema::getCurrentThisType() is a type of 'this' for nested lambda.<br>
<br>
This patch addresses this issue and makes RebuildLambdaScopeInfo() compute the correct 'this' type.<br>
<br>
<a href="http://reviews.llvm.org/D20349" rel="noreferrer" target="_blank">http://reviews.llvm.org/D20349</a><br>
<br>
Files:<br>
  lib/Sema/SemaDecl.cpp<br>
<br>
Index: lib/Sema/SemaDecl.cpp<br>
===================================================================<br>
--- lib/Sema/SemaDecl.cpp<br>
+++ lib/Sema/SemaDecl.cpp<br>
@@ -11109,8 +11109,16 @@<br>
           CaptureType, /*Expr*/ nullptr);<br>
<br>
     } else if (C.capturesThis()) {<br>
+      QualType ThisTy = CallOperator->getThisType(S.Context);<br>
+      QualType BaseTy = ThisTy->getPointeeType();<br>
+      if (C.getCaptureKind() == LCK_StarThis &&<br>
+          CallOperator->isConst() &&<br>
+          !BaseTy.isConstQualified()) {<br>
+        BaseTy.addConst();<br>
+        ThisTy = S.Context.getPointerType(BaseTy);<br>
+      }<br>
       LSI->addThisCapture(/*Nested*/ false, C.getLocation(),<br>
-                              S.getCurrentThisType(), /*Expr*/ nullptr,<br>
+                              ThisTy, /*Expr*/ nullptr,<br>
                               C.getCaptureKind() == LCK_StarThis);<br>
     } else {<br>
       LSI->addVLATypeCapture(C.getLocation(), I->getType());<br>
<br>
<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>