[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:32 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());
+ } else {
+ while (PendingLazyContextDecls.size() > Rec.LazyContextDeclPos) {
+ Decl *D = PendingLazyContextDecls.pop_back_val();
+ setContextDecl(*this, D, nullptr);
----------------
zyn0217 wrote:
Is there anything special for the third argument being null? Both `setLambdaContextDecl()` and `handleLambdaNumbering()` would bail out for such cases, right?
https://github.com/llvm/llvm-project/pull/107942
More information about the cfe-commits
mailing list