From 1cdb738fe574b0c1fb1edf71951eb7e9aadacc31 Mon Sep 17 00:00:00 2001 From: "petro.zarytskyi" Date: Tue, 11 Jun 2024 17:50:19 +0300 Subject: [PATCH] Don't use original expressions when cloning binary operators in the reverse mode --- lib/Differentiator/ReverseModeVisitor.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index dffd119f1..759abe28a 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -2248,20 +2248,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // For x, AssignedDiff is _d_x, for x[i] its _d_x[i], for reference exprs // like (x = y) it propagates recursively, so _d_x is also returned. Expr* AssignedDiff = Ldiff.getExpr_dx(); - if (!AssignedDiff) { - // If either LHS or RHS is a declaration reference, visit it to avoid - // naming collision - auto* LDRE = dyn_cast(L); - auto* RDRE = dyn_cast(R); - - if (!LDRE && !RDRE) - return Clone(BinOp); - - Expr* LExpr = LDRE ? Visit(L).getExpr() : L; - Expr* RExpr = RDRE ? Visit(R).getExpr() : R; - - return BuildOp(opCode, LExpr, RExpr); - } + if (!AssignedDiff) + return Clone(BinOp); ResultRef = AssignedDiff; // If assigned expr is dependent, first update its derivative; auto Lblock_begin = Lblock->body_rbegin();