[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-09-07 Thread Yuanfang Chen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG61d1cce2f835: PR45881: Properly use CXXThisOverride for 
templated lambda (authored by ychen).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
  clang/test/SemaCXX/cxx20-lambda-decltype-this.cpp

Index: clang/test/SemaCXX/cxx20-lambda-decltype-this.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-lambda-decltype-this.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -emit-llvm-only %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fdelayed-template-parsing %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fms-extensions %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fdelayed-template-parsing -fms-extensions %s
+
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+
+struct B {
+void f();
+};
+void B::f() {
+auto z = [](){return 0;};
+z.template operator()();
+}
+
+struct C {
+void f();
+};
+void C::f() {
+auto z = [](){return 0;};
+z.template operator()();
+}
+} // namespace PR45881
Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -298,3 +298,13 @@
 
 } // namespace PR32831
 
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+} // namespace PR45881
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2858,9 +2858,24 @@
   return Sema::TDK_Incomplete;
 }
 
-TemplateArgumentLoc DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
-TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
-HasDefaultArg);
+TemplateArgumentLoc DefArg;
+{
+  Qualifiers ThisTypeQuals;
+  CXXRecordDecl *ThisContext = nullptr;
+  if (auto *Rec = dyn_cast(TD->getDeclContext()))
+if (Rec->isLambda())
+  if (auto *Method = dyn_cast(Rec->getDeclContext())) {
+ThisContext = Method->getParent();
+ThisTypeQuals = Method->getMethodQualifiers();
+  }
+
+  Sema::CXXThisScopeRAII ThisScope(S, ThisContext, ThisTypeQuals,
+   S.getLangOpts().CPlusPlus17);
+
+  DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
+  TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
+  HasDefaultArg);
+}
 
 // If there was no default argument, deduction is incomplete.
 if (DefArg.getArgument().isNull()) {
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5110,7 +5110,11 @@
 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
   TemplateArgLists.addOuterTemplateArguments(None);
 
-Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
+bool ForLambdaCallOperator = false;
+if (const auto *Rec = dyn_cast(Template->getDeclContext()))
+  ForLambdaCallOperator = Rec->isLambda();
+Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext(),
+   !ForLambdaCallOperator);
 ArgType =
 SemaRef.SubstType(ArgType, TemplateArgLists,
   Param->getDefaultArgumentLoc(), Param->getDeclName());
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1137,11 +1137,10 @@
 }
   }
 
-  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
-  // happen during instantiation of its nested generic lambda call operator)
-  if (isLambdaCallOperator(CurDC)) {
-assert(CurLSI && "While computing 'this' capture-type for a generic "
- "lambda, we must have a corresponding LambdaScopeInfo");
+  // 2) We've run out of ScopeInfos but check 1. if CurDC is a lambda (which
+  //can happen during instantiation of its nested generic lambda call
+  //operator); 2. if we're in a lambda scope (lambda body).
+  if (CurLSI && isLambdaCallOperator(CurDC)) {
 assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) &&
"While computing 'this' capture-type for a generic lambda, when 

[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-09-07 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

> I'll commit this by the end of the day if @rsmith wasn't able to take a look.

Sounds good, thank you very much!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-09-07 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D102531#2987367 , @gulfem wrote:

> Any update on this review? Our builds are still broken.

I'll commit this by the end of the day if @rsmith wasn't able to take a look.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-09-07 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

Any update on this review? Our builds are still broken.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-09-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, but please wait a day or so before landing in case @rsmith spots 
something I've missed (the only change I wasn't 100% certain on was lifting the 
assert predicate; it seems correct to me, but I'm wary of removing asserts).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-09-01 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

@aaron.ballman would it be possible for you to review this patch, so we can fix 
our broken builds?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-09-01 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

We recently enabled assertions in our Fuchsia builds, and our builds started to 
fail:

  FAILED: obj/src/lib/storage/vfs/cpp/libcpp.fuchsia_vfs.cc.o
  ../../../recipe_cleanup/clangLhcV7J/bin/clang++ -MD -MF 
obj/src/lib/storage/vfs/cpp/libcpp.fuchsia_vfs.cc.o.d 
-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS 
-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -…
  clang++: clang/lib/Sema/SemaExprCXX.cpp:1144: clang::QualType 
adjustCVQualifiersForCXXThisWithinLambda(ArrayRef, clang::QualType, clang::DeclContext *, clang::ASTC…
  clang++: error: clang frontend command failed with exit code 134 (use -v to 
see invocation)

https://luci-milo.appspot.com/ui/p/fuchsia/builders/ci/clang_toolchain.core.x64-debug/b8837288282633988801/overview

This patch seems to be fixing the issue that we are running.
Is there a way to speed up the process in this review, so our broken builds can 
be fixed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-07-06 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 356796.
ychen added a comment.

- address feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
  clang/test/SemaCXX/cxx20-lambda-decltype-this.cpp

Index: clang/test/SemaCXX/cxx20-lambda-decltype-this.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-lambda-decltype-this.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -emit-llvm-only %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fdelayed-template-parsing %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fms-extensions %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fdelayed-template-parsing -fms-extensions %s
+
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+
+struct B {
+void f();
+};
+void B::f() {
+auto z = [](){return 0;};
+z.template operator()();
+}
+
+struct C {
+void f();
+};
+void C::f() {
+auto z = [](){return 0;};
+z.template operator()();
+}
+} // namespace PR45881
Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -298,3 +298,13 @@
 
 } // namespace PR32831
 
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+} // namespace PR45881
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2858,9 +2858,24 @@
   return Sema::TDK_Incomplete;
 }
 
-TemplateArgumentLoc DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
-TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
-HasDefaultArg);
+TemplateArgumentLoc DefArg;
+{
+  Qualifiers ThisTypeQuals;
+  CXXRecordDecl *ThisContext = nullptr;
+  if (auto *Rec = dyn_cast(TD->getDeclContext()))
+if (Rec->isLambda())
+  if (auto *Method = dyn_cast(Rec->getDeclContext())) {
+ThisContext = Method->getParent();
+ThisTypeQuals = Method->getMethodQualifiers();
+  }
+
+  Sema::CXXThisScopeRAII ThisScope(S, ThisContext, ThisTypeQuals,
+   S.getLangOpts().CPlusPlus17);
+
+  DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
+  TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
+  HasDefaultArg);
+}
 
 // If there was no default argument, deduction is incomplete.
 if (DefArg.getArgument().isNull()) {
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5110,7 +5110,11 @@
 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
   TemplateArgLists.addOuterTemplateArguments(None);
 
-Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
+bool ForLambdaCallOperator = false;
+if (const auto *Rec = dyn_cast(Template->getDeclContext()))
+  ForLambdaCallOperator = Rec->isLambda();
+Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext(),
+   !ForLambdaCallOperator);
 ArgType =
 SemaRef.SubstType(ArgType, TemplateArgLists,
   Param->getDefaultArgumentLoc(), Param->getDeclName());
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1137,11 +1137,10 @@
 }
   }
 
-  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
-  // happen during instantiation of its nested generic lambda call operator)
-  if (isLambdaCallOperator(CurDC)) {
-assert(CurLSI && "While computing 'this' capture-type for a generic "
- "lambda, we must have a corresponding LambdaScopeInfo");
+  // 2) We've run out of ScopeInfos but check 1. if CurDC is a lambda (which
+  //can happen during instantiation of its nested generic lambda call
+  //operator); 2. if we're in a lambda scope (lambda body).
+  if (CurLSI && isLambdaCallOperator(CurDC)) {
 assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) &&
"While computing 'this' capture-type for a generic lambda, when we "
"run out of enclosing LSI's, yet the enclosing DC is a "

[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-07-06 Thread Raul Tambre via Phabricator via cfe-commits
tambre added inline comments.



Comment at: clang/test/SemaCXX/cxx2a-lambda-decltype-this.cpp:1-4
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -emit-llvm-only %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks 
-fdelayed-template-parsing %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -fms-extensions %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks 
-fdelayed-template-parsing -fms-extensions %s

`-fblocks` doesn't seem like it'd be necessary?

It would probably be a good idea to rename this to 
`cxx20-lambda-decltype-this.cpp` and use `-std=c++20` from the get-go since 
C++20 has been finalized.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-06-08 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-05-25 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

ping...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-05-17 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 346010.
ychen added a comment.

- Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
  clang/test/SemaCXX/cxx2a-lambda-decltype-this.cpp

Index: clang/test/SemaCXX/cxx2a-lambda-decltype-this.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-lambda-decltype-this.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -emit-llvm-only %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -fdelayed-template-parsing %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -fms-extensions %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s
+
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+
+struct B {
+void f();
+};
+void B::f() {
+auto z = [](){return 0;};
+z.template operator()();
+}
+
+struct C {
+void f();
+};
+void C::f() {
+auto z = [](){return 0;};
+z.template operator()();
+}
+} // namespace PR45881
Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -298,3 +298,13 @@
 
 } // namespace PR32831
 
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+} // namespace PR45881
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2858,9 +2858,24 @@
   return Sema::TDK_Incomplete;
 }
 
-TemplateArgumentLoc DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
-TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
-HasDefaultArg);
+TemplateArgumentLoc DefArg;
+{
+  Qualifiers ThisTypeQuals;
+  CXXRecordDecl *ThisContext = nullptr;
+  if (auto *Rec = dyn_cast(TD->getDeclContext()))
+if (Rec->isLambda())
+  if (auto *Method = dyn_cast(Rec->getDeclContext())) {
+ThisContext = Method->getParent();
+ThisTypeQuals = Method->getMethodQualifiers();
+  }
+
+  Sema::CXXThisScopeRAII ThisScope(S, ThisContext, ThisTypeQuals,
+   S.getLangOpts().CPlusPlus17);
+
+  DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
+  TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
+  HasDefaultArg);
+}
 
 // If there was no default argument, deduction is incomplete.
 if (DefArg.getArgument().isNull()) {
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5090,7 +5090,11 @@
 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
   TemplateArgLists.addOuterTemplateArguments(None);
 
-Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
+bool ForLambdaCallOperator = false;
+if (const auto *Rec = dyn_cast(Template->getDeclContext()))
+  ForLambdaCallOperator = Rec->isLambda();
+Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext(),
+   !ForLambdaCallOperator);
 ArgType =
 SemaRef.SubstType(ArgType, TemplateArgLists,
   Param->getDefaultArgumentLoc(), Param->getDeclName());
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1119,11 +1119,10 @@
 }
   }
 
-  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
-  // happen during instantiation of its nested generic lambda call operator)
-  if (isLambdaCallOperator(CurDC)) {
-assert(CurLSI && "While computing 'this' capture-type for a generic "
- "lambda, we must have a corresponding LambdaScopeInfo");
+  // 2) We've run out of ScopeInfos but check 1. if CurDC is a lambda (which
+  //can happen during instantiation of its nested generic lambda call
+  //operator); 2. if we're in a lambda scope (lambda body).
+  if (CurLSI && isLambdaCallOperator(CurDC)) {
 assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) &&
"While computing 'this' capture-type for a generic lambda, when we "
"run out of enclosing LSI's, yet the enclosing 

[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-05-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Mostly just superficial comments from me at this point.




Comment at: clang/lib/Sema/SemaTemplate.cpp:5094-5095
+bool ForLambdaCallOperator = false;
+if (CXXRecordDecl *Rec =
+dyn_cast(Template->getDeclContext()))
+  ForLambdaCallOperator = Rec->isLambda();





Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:2865
+  CXXRecordDecl *ThisContext = nullptr;
+  if (CXXRecordDecl *Rec = dyn_cast(TD->getDeclContext()))
+if (Rec->isLambda())





Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:2867
+if (Rec->isLambda())
+  if (CXXMethodDecl *Method =
+  dyn_cast(Rec->getDeclContext())) {




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102531/new/

https://reviews.llvm.org/D102531

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-05-14 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen created this revision.
ychen added reviewers: rsmith, faisalv, aaron.ballman.
ychen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- `this` used in lambda expression parameter declarations needs no capture.
- Set up CXXThisOverride for default template arguments of a lambda.

A similar fix to this is c3d2ebb60f604.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102531

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
  clang/test/SemaCXX/cxx2a-lambda-decltype-this.cpp

Index: clang/test/SemaCXX/cxx2a-lambda-decltype-this.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-lambda-decltype-this.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -emit-llvm-only %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -fdelayed-template-parsing %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -fms-extensions %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s
+
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+
+struct B {
+void f();
+};
+void B::f() {
+auto z = [](){return 0;};
+z.template operator()();
+}
+
+struct C {
+void f();
+};
+void C::f() {
+auto z = [](){return 0;};
+z.template operator()();
+}
+} // namespace PR45881
Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -298,3 +298,13 @@
 
 } // namespace PR32831
 
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+} // namespace PR45881
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2858,9 +2858,25 @@
   return Sema::TDK_Incomplete;
 }
 
-TemplateArgumentLoc DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
-TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
-HasDefaultArg);
+TemplateArgumentLoc DefArg;
+{
+  Qualifiers ThisTypeQuals;
+  CXXRecordDecl *ThisContext = nullptr;
+  if (CXXRecordDecl *Rec = dyn_cast(TD->getDeclContext()))
+if (Rec->isLambda())
+  if (CXXMethodDecl *Method =
+  dyn_cast(Rec->getDeclContext())) {
+ThisContext = Method->getParent();
+ThisTypeQuals = Method->getMethodQualifiers();
+  }
+
+  Sema::CXXThisScopeRAII ThisScope(S, ThisContext, ThisTypeQuals,
+   S.getLangOpts().CPlusPlus17);
+
+  DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
+  TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
+  HasDefaultArg);
+}
 
 // If there was no default argument, deduction is incomplete.
 if (DefArg.getArgument().isNull()) {
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5090,7 +5090,12 @@
 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
   TemplateArgLists.addOuterTemplateArguments(None);
 
-Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
+bool ForLambdaCallOperator = false;
+if (CXXRecordDecl *Rec =
+dyn_cast(Template->getDeclContext()))
+  ForLambdaCallOperator = Rec->isLambda();
+Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext(),
+   !ForLambdaCallOperator);
 ArgType =
 SemaRef.SubstType(ArgType, TemplateArgLists,
   Param->getDefaultArgumentLoc(), Param->getDeclName());
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1119,11 +1119,10 @@
 }
   }
 
-  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
-  // happen during instantiation of its nested generic lambda call operator)
-  if (isLambdaCallOperator(CurDC)) {
-assert(CurLSI && "While computing 'this' capture-type for a generic "
- "lambda, we must have a corresponding LambdaScopeInfo");
+  // 2) We've run out of ScopeInfos but check 1. if CurDC is a lambda (which
+  //can happen during instantiation of its nested generic lambda call
+  //operator); 2. if we're in a lambda scope