twoh created this revision. twoh added reviewers: faisalv, rsmith. twoh added a subscriber: cfe-commits.
(This is a fix for Bug 27797 https://llvm.org/bugs/show_bug.cgi?id=27797). 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. 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. This patch addresses this issue and makes RebuildLambdaScopeInfo() compute the correct 'this' type. http://reviews.llvm.org/D20349 Files: lib/Sema/SemaDecl.cpp Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -11109,8 +11109,16 @@ CaptureType, /*Expr*/ nullptr); } else if (C.capturesThis()) { + QualType ThisTy = CallOperator->getThisType(S.Context); + QualType BaseTy = ThisTy->getPointeeType(); + if (C.getCaptureKind() == LCK_StarThis && + CallOperator->isConst() && + !BaseTy.isConstQualified()) { + BaseTy.addConst(); + ThisTy = S.Context.getPointerType(BaseTy); + } LSI->addThisCapture(/*Nested*/ false, C.getLocation(), - S.getCurrentThisType(), /*Expr*/ nullptr, + ThisTy, /*Expr*/ nullptr, C.getCaptureKind() == LCK_StarThis); } else { LSI->addVLATypeCapture(C.getLocation(), I->getType());
Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -11109,8 +11109,16 @@ CaptureType, /*Expr*/ nullptr); } else if (C.capturesThis()) { + QualType ThisTy = CallOperator->getThisType(S.Context); + QualType BaseTy = ThisTy->getPointeeType(); + if (C.getCaptureKind() == LCK_StarThis && + CallOperator->isConst() && + !BaseTy.isConstQualified()) { + BaseTy.addConst(); + ThisTy = S.Context.getPointerType(BaseTy); + } LSI->addThisCapture(/*Nested*/ false, C.getLocation(), - S.getCurrentThisType(), /*Expr*/ nullptr, + ThisTy, /*Expr*/ nullptr, C.getCaptureKind() == LCK_StarThis); } else { LSI->addVLATypeCapture(C.getLocation(), I->getType());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits