Skip to content

Commit

Permalink
Move dfdx() check in init list further down to avoid cloning of ILE
Browse files Browse the repository at this point in the history
  • Loading branch information
kchristin22 committed Nov 20, 2024
1 parent b5f381a commit 7f41368
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,8 +1480,6 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
}

StmtDiff ReverseModeVisitor::VisitInitListExpr(const InitListExpr* ILE) {
if (!dfdx())
return StmtDiff(Clone(ILE));
QualType ILEType = ILE->getType();
llvm::SmallVector<Expr*, 16> clonedExprs(ILE->getNumInits());
if (isArrayOrPointerType(ILEType)) {
Expand All @@ -1506,8 +1504,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
// fetch ith field of the struct.
auto field_iterator = ILEType->getAsCXXRecordDecl()->field_begin();
std::advance(field_iterator, i);
Expr* member_acess = utils::BuildMemberExpr(
m_Sema, getCurrentScope(), dfdx(), (*field_iterator)->getName());
Expr* member_acess = nullptr;
if (dfdx())
member_acess = utils::BuildMemberExpr(
m_Sema, getCurrentScope(), dfdx(), (*field_iterator)->getName());
clonedExprs[i] = Visit(ILE->getInit(i), member_acess).getExpr();
}
Expr* clonedILE = m_Sema.ActOnInitList(noLoc, clonedExprs, noLoc).get();
Expand Down

0 comments on commit 7f41368

Please sign in to comment.