Skip to content

Commit

Permalink
Move if-stmt invariant code outside, fix a compiler warning. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Dec 7, 2023
1 parent 232d17b commit 736df53
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,24 +1304,18 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
}

StmtDiff ReverseModeVisitor::VisitDeclRefExpr(const DeclRefExpr* DRE) {
DeclRefExpr* clonedDRE = nullptr;
DeclRefExpr* clonedDRE = cast<DeclRefExpr>(Clone(DRE));
// Check if referenced Decl was "replaced" with another identifier inside
// the derivative
if (const auto* VD = dyn_cast<VarDecl>(DRE->getDecl())) {
clonedDRE = cast<DeclRefExpr>(Clone(DRE));
if (const 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 (clonedDRE->getDecl()->getDeclContext() != m_Sema.CurContext) {
auto* referencedDecl = cast<VarDecl>(clonedDRE->getDecl());
clonedDRE = cast<DeclRefExpr>(BuildDeclRef(referencedDecl));
}
} else
clonedDRE = cast<DeclRefExpr>(Clone(DRE));
if (VD->getDeclContext() != m_Sema.CurContext)
clonedDRE = cast<DeclRefExpr>(BuildDeclRef(VD));

if (auto* decl = dyn_cast<VarDecl>(clonedDRE->getDecl())) {
if (isVectorValued) {
if (m_VectorOutput.size() <= outputArrayCursor)
return StmtDiff(clonedDRE);
Expand Down

0 comments on commit 736df53

Please sign in to comment.