Skip to content

Commit

Permalink
Don't use original expressions when cloning binary operators in the r…
Browse files Browse the repository at this point in the history
…everse mode
  • Loading branch information
PetroZarytskyi authored and vgvassilev committed Jun 14, 2024
1 parent db0a949 commit 1cdb738
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeclRefExpr>(L);
auto* RDRE = dyn_cast<DeclRefExpr>(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();
Expand Down

0 comments on commit 1cdb738

Please sign in to comment.