================
@@ -17658,8 +17662,49 @@ HandleImmediateInvocations(Sema &SemaRef,
   }
 }
 
+static void setContextDecl(Sema &S, Decl *Base, Decl *ContextDecl) {
+  switch (Base->getKind()) {
+  case Decl::CXXRecord: {
+    auto *RD = cast<CXXRecordDecl>(Base);
+    RD->setLambdaContextDecl(ContextDecl);
+    S.handleLambdaNumbering(RD, RD->getLambdaCallOperator(),
+                            /*NumberingOverride=*/std::nullopt,
+                            /*InSignature=*/true);
+  } break;
+  case Decl::RequiresExprBody:
+    cast<RequiresExprBodyDecl>(Base)->setContextDecl(ContextDecl);
+    break;
+  default:
+    llvm_unreachable("Undexpected Decl Kind");
+  }
+}
+
+void Sema::UpdateCurrentContextDecl(Decl *ContextDecl) {
+  assert(ContextDecl);
+  ExpressionEvaluationContextRecord &Rec = ExprEvalContexts.back();
+  assert(!Rec.ContextDecl.hasValue());
+  assert(Rec.LazyContextDeclPos <= PendingLazyContextDecls.size());
+  Rec.ContextDecl = ContextDecl;
+  while (PendingLazyContextDecls.size() > Rec.LazyContextDeclPos)
+    setContextDecl(*this, PendingLazyContextDecls.pop_back_val(), ContextDecl);
+}
+
 void Sema::PopExpressionEvaluationContext() {
   ExpressionEvaluationContextRecord& Rec = ExprEvalContexts.back();
+  assert(Rec.LazyContextDeclPos <= PendingLazyContextDecls.size());
+  if (!Rec.HasReusedDeclContext) {
+    if (Rec.ContextDecl.hasValue()) {
+      assert(Rec.LazyContextDeclPos == PendingLazyContextDecls.size());
----------------
zyn0217 wrote:

Is this an assumption for that

1. if the lambda (or something else we want to later add context decl for) is 
aware of its parent context decl at the point of its creation, then there 
should not be any pointer in `PendingLazyContextDecls` tracking the lambda.

2. the subsequent on-stack evaluation contexts should have handled 
PendingLazyContextDecls properly

https://github.com/llvm/llvm-project/pull/107942
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to