Skip to content

Commit

Permalink
Make EvaluateAsConstantExpr work across versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Aug 4, 2023
1 parent 7d8b432 commit 0794d64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions include/clad/Differentiator/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ static inline bool Expr_EvaluateAsInt(const Expr *E,
#endif
}

// Clang 12: bool Expr::EvaluateAsConstantExpr(EvalResult &Result,
// ConstExprUsage Usage, ASTContext &)
// => bool Expr::EvaluateAsConstantExpr(EvalResult &Result, ASTContext &)

static inline bool Expr_EvaluateAsConstantExpr(const Expr* E,
Expr::EvalResult& res,
const ASTContext& Ctx) {
#if CLANG_VERSION_MAJOR < 12
return E->EvaluateAsConstantExpr(res, Expr::EvaluateForCodeGen, Ctx);
#else
return E->EvaluateAsConstantExpr(res, Ctx);
#endif
}

// Compatibility helper function for creation IfStmt.
// Clang 8 and above use Create.
// Clang 12 and above use two extra params.
Expand Down
3 changes: 2 additions & 1 deletion lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2744,7 +2744,8 @@ std::vector<Expr*> ReverseModeVisitor::GetInnermostReturnExpr(Expr* E) {
if (!UsefulToStoreGlobal(E)) {
Expr* Cloned = Clone(E);
Expr::EvalResult evalRes;
bool isConst = E->EvaluateAsConstantExpr(evalRes, m_Context);
bool isConst =
clad_compat::Expr_EvaluateAsConstantExpr(E, evalRes, m_Context);
return DelayedStoreResult{*this, StmtDiff{Cloned, Cloned},
/*isConstant*/ isConst,
/*isInsideLoop*/ false,
Expand Down

0 comments on commit 0794d64

Please sign in to comment.