Skip to content

Commit

Permalink
Simplify logic. NFC.
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Dec 15, 2024
1 parent b36eae9 commit f6867a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Differentiator/BaseForwardModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VarDecl>(clonedDRE->getDecl());
clonedDRE = BuildDeclRef(referencedDecl, NNS);
}
Expand Down
10 changes: 4 additions & 6 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,20 +1400,18 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
}

StmtDiff ReverseModeVisitor::VisitDeclRefExpr(const DeclRefExpr* DRE) {
Expr* clonedDRE = Clone(DRE);
auto* clonedDRE = cast<DeclRefExpr>(Clone(DRE));
// Check if referenced Decl was "replaced" with another identifier inside
// the derivative
if (auto* VD = dyn_cast<VarDecl>(cast<DeclRefExpr>(clonedDRE)->getDecl())) {
if (auto* VD = dyn_cast<VarDecl>(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<DeclRefExpr>(clonedDRE);
NestedNameSpecifier* NNS = DRE->getQualifier();
auto* referencedDecl = cast<VarDecl>(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
Expand Down

0 comments on commit f6867a2

Please sign in to comment.