[clang] [clang-tools-extra] [llvm] [clang] WIP: Improved Context Declaration tracking (PR #107942)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 6 00:44:31 PST 2024
================
@@ -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
More information about the cfe-commits
mailing list