clad icon indicating copy to clipboard operation
clad copied to clipboard

Reversing statement order twice in DifferentiateSingleStmt

Open PetroZarytskyi opened this issue 1 year ago • 0 comments

In ReverseModeVisitor::DifferentiateSingleStmt, we end the reverse pass block and then reverse it:

CompoundStmt* RCS = endBlock(direction::reverse);
std::reverse(RCS->body_begin(), RCS->body_end());

The problem is that endBlock itself reverses the order of statements:

auto* CS = MakeCompoundStmt(getCurrentBlock(direction::reverse));
std::reverse(CS->body_begin(), CS->body_end());

So eventually, the order is reversed twice. This behavior is probably not intended. From what I've seen, this has the biggest impact on visiting binary operators. Removing the reversing in DifferentiateSingleStmt will affect the logic in VisitBinaryOperator a lot.

PetroZarytskyi avatar Nov 24 '23 16:11 PetroZarytskyi