clad
clad copied to clipboard
Reversing statement order twice in DifferentiateSingleStmt
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.