From 62f93fd7c72494f08b1787067adfcb2f5910f6ad Mon Sep 17 00:00:00 2001 From: kchristin Date: Wed, 20 Nov 2024 18:32:57 +0200 Subject: [PATCH] Move dfdx() check in init list further down to avoid cloning of ILE --- lib/Differentiator/ReverseModeVisitor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index 785498a07..41a81e169 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -1277,8 +1277,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 clonedExprs(ILE->getNumInits()); if (isArrayOrPointerType(ILEType)) { @@ -1303,8 +1301,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();