https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/183690
Move the `!VD` case up so we can assume `VD` to be non-null earlier and use a local variable instead of calling `D->getType()` several times. >From cc2a1b053fafdbef8ec1ff501f7dbdd30f731b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Fri, 27 Feb 2026 07:37:19 +0100 Subject: [PATCH] [clang][bytecode][NFC] Refactor visitDeclRef() --- clang/lib/AST/ByteCode/Compiler.cpp | 32 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 9727d95c00119..cd23d0eb5d344 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -7208,14 +7208,15 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { // pointing to a reference, we need to get its value directly (i.e. the // pointer to the actual value) instead of a pointer to the pointer to the // value. - bool IsReference = D->getType()->isReferenceType(); + QualType DeclType = D->getType(); + bool IsReference = DeclType->isReferenceType(); // Function parameters. // Note that it's important to check them first since we might have a local // variable created for a ParmVarDecl as well. if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) { if (Ctx.getLangOpts().CPlusPlus && !Ctx.getLangOpts().CPlusPlus11 && - !D->getType()->isIntegralOrEnumerationType()) { + !DeclType->isIntegralOrEnumerationType()) { return this->emitInvalidDeclRef(cast<DeclRefExpr>(E), /*InitializerFailed=*/false, E); } @@ -7290,20 +7291,19 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { // Try to lazily visit (or emit dummy pointers for) declarations // we haven't seen yet. + const auto *VD = dyn_cast<VarDecl>(D); + if (!VD) + return this->emitDummyPtr(D, E); + // For C. if (!Ctx.getLangOpts().CPlusPlus) { - if (const auto *VD = dyn_cast<VarDecl>(D); - VD && VD->getAnyInitializer() && - VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak()) + if (VD && VD->getAnyInitializer() && + DeclType.isConstant(Ctx.getASTContext()) && !VD->isWeak()) return revisit(VD); return this->emitDummyPtr(D, E); } // ... and C++. - const auto *VD = dyn_cast<VarDecl>(D); - if (!VD) - return this->emitDummyPtr(D, E); - const auto typeShouldBeVisited = [&](QualType T) -> bool { if (T.isConstant(Ctx.getASTContext())) return true; @@ -7311,7 +7311,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { }; if ((VD->hasGlobalStorage() || VD->isStaticDataMember()) && - typeShouldBeVisited(VD->getType())) { + typeShouldBeVisited(DeclType)) { if (const Expr *Init = VD->getAnyInitializer(); Init && !Init->isValueDependent()) { // Whether or not the evaluation is successul doesn't really matter @@ -7330,8 +7330,8 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { // it will ultimately call into Context::evaluateAsInitializer(). In // other words, we're evaluating the initializer, just to know if we can // evaluate the initializer. - if (VD->isLocalVarDecl() && typeShouldBeVisited(VD->getType()) && - VD->getInit() && !VD->getInit()->isValueDependent()) { + if (VD->isLocalVarDecl() && typeShouldBeVisited(DeclType) && VD->getInit() && + !VD->getInit()->isValueDependent()) { if (VD->evaluateValue()) { // Revisit the variable declaration, but make sure it's associated with a // different evaluation, so e.g. mutable reads don't work on it. @@ -7339,11 +7339,9 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { return revisit(VD); } - if (!IsReference) - return this->emitDummyPtr(D, E); - - return this->emitInvalidDeclRef(cast<DeclRefExpr>(E), - /*InitializerFailed=*/true, E); + if (IsReference) + return this->emitInvalidDeclRef(cast<DeclRefExpr>(E), + /*InitializerFailed=*/true, E); } return this->emitDummyPtr(D, E); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
