Skip to content

Commit

Permalink
Take __real/__imag operators into account in TBR analysis and Get…
Browse files Browse the repository at this point in the history
…InnermostReturnExpr.
  • Loading branch information
PetroZarytskyi committed Nov 22, 2023
1 parent f11bf1e commit 7cd0a1c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Differentiator/CladUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,14 @@ namespace clad {
auto opCode = UnOp->getOpcode();
if (opCode == clang::UO_PreInc || opCode == clang::UO_PreDec)
Visit(UnOp->getSubExpr());
else if (opCode == UnaryOperatorKind::UO_Real ||
opCode == UnaryOperatorKind::UO_Imag) {
/// FIXME: Considering real/imaginary part atomic is
/// not always correct since the subexpression can
/// be more complex than just a DeclRefExpr.
/// (e.g. `__real (n++ ? z1 : z2)`)
m_Exprs.push_back(UnOp);
}
}

void VisitDeclRefExpr(clang::DeclRefExpr* DRE) {
Expand Down
5 changes: 5 additions & 0 deletions lib/Differentiator/TBRAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,11 @@ bool TBRAnalyzer::VisitUnaryOperator(clang::UnaryOperator* UnOp) {
markLocation(innerExpr);
}
}
/// FIXME: Ideally, `__real` and `__imag` operators should be
/// treated as member expressions. However, it is not clear
/// where the FieldDecls of real and imaginary parts should be
/// deduced from (their names might be compiler-specific).
/// So for now we visit the whole subexpression.
return true;
}

Expand Down

0 comments on commit 7cd0a1c

Please sign in to comment.