================
@@ -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());
+    } else {
+      while (PendingLazyContextDecls.size() > Rec.LazyContextDeclPos) {
+        Decl *D = PendingLazyContextDecls.pop_back_val();
+        setContextDecl(*this, D, nullptr);
----------------
mizvekov wrote:

This is the error path. Basically we had a bunch of declarations waiting for 
their parents to be created, but for some reason we bailed out and we are never 
going to create their parents anymore.

Before this patch, these declarations would have stayed parented to their 
parent's parent.

These declarations would never make it to codegen, so don't matter much except 
for analysis.
The upside is that by staying as lazycontext entities, we don't lose track of 
their template depth.

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