From f6867a2c41da24a0fd372243e936b648f681a0ba Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sun, 15 Dec 2024 18:39:58 +0000 Subject: [PATCH] Simplify logic. NFC. --- lib/Differentiator/BaseForwardModeVisitor.cpp | 2 +- lib/Differentiator/ReverseModeVisitor.cpp | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/Differentiator/BaseForwardModeVisitor.cpp b/lib/Differentiator/BaseForwardModeVisitor.cpp index 4a9c81412..aeb43ddb4 100644 --- a/lib/Differentiator/BaseForwardModeVisitor.cpp +++ b/lib/Differentiator/BaseForwardModeVisitor.cpp @@ -1036,7 +1036,7 @@ StmtDiff BaseForwardModeVisitor::VisitDeclRefExpr(const DeclRefExpr* DRE) { // Sema::BuildDeclRefExpr is responsible for adding captured fields // to the underlying struct of a lambda. if (clonedDRE->getDecl()->getDeclContext() != m_Sema.CurContext) { - NestedNameSpecifier* NNS = DRE->getQualifier(); + NestedNameSpecifier* NNS = clonedDRE->getQualifier(); auto* referencedDecl = cast(clonedDRE->getDecl()); clonedDRE = BuildDeclRef(referencedDecl, NNS); } diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index a7d4dc6cb..7ba94b555 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -1400,20 +1400,18 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } StmtDiff ReverseModeVisitor::VisitDeclRefExpr(const DeclRefExpr* DRE) { - Expr* clonedDRE = Clone(DRE); + auto* clonedDRE = cast(Clone(DRE)); // Check if referenced Decl was "replaced" with another identifier inside // the derivative - if (auto* VD = dyn_cast(cast(clonedDRE)->getDecl())) { + if (auto* VD = dyn_cast(clonedDRE->getDecl())) { // If current context is different than the context of the original // declaration (e.g. we are inside lambda), rebuild the DeclRefExpr // with Sema::BuildDeclRefExpr. This is required in some cases, e.g. // Sema::BuildDeclRefExpr is responsible for adding captured fields // to the underlying struct of a lambda. if (VD->getDeclContext() != m_Sema.CurContext) { - auto* ccDRE = dyn_cast(clonedDRE); - NestedNameSpecifier* NNS = DRE->getQualifier(); - auto* referencedDecl = cast(ccDRE->getDecl()); - clonedDRE = BuildDeclRef(referencedDecl, NNS, DRE->getValueKind()); + NestedNameSpecifier* NNS = clonedDRE->getQualifier(); + clonedDRE = BuildDeclRef(VD, NNS, clonedDRE->getValueKind()); } // This case happens when ref-type variables have to become function // global. Ref-type declarations cannot be moved to the function global