Skip to content

Commit

Permalink
Implement visitor to check varied expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Andriychuk committed Nov 6, 2024
1 parent 90d17a0 commit 7061c34
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
11 changes: 5 additions & 6 deletions lib/Differentiator/DiffPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,13 +627,12 @@ namespace clad {
ArrayRef<ParmVarDecl*> FDparam = Function->parameters();
std::vector<ParmVarDecl*> derivedParam;

for(auto* parameter: FDparam){
for (auto* parameter : FDparam) {
QualType parType = parameter->getType();
if(parType->isPointerType()){
if(!parType->getPointeeType().isConstQualified())
derivedParam.push_back(parameter);
}else if(!parType.isConstQualified())
derivedParam.push_back(parameter);
while (parType->isPointerType())
parType = parType->getPointeeType();
if (!parType.isConstQualified())
derivedParam.push_back(parameter);
}

std::copy(derivedParam.begin(), derivedParam.end(),
Expand Down
19 changes: 18 additions & 1 deletion lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,24 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
// subexpression.
if (const auto* MTE = dyn_cast<MaterializeTemporaryExpr>(arg))
arg = clad_compat::GetSubExpr(MTE)->IgnoreImpCasts();
if (!arg->isEvaluatable(m_Context)) {
class VariedChecker : public RecursiveASTVisitor<VariedChecker> {
const DiffRequest& Request;

public:
VariedChecker(const DiffRequest& DR) : Request(DR) {}
bool isVariedE(const clang::Expr* E) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return !TraverseStmt(const_cast<clang::Expr*>(E));
}
bool VisitDeclRefExpr(const clang::DeclRefExpr* DRE) {
if (!isa<VarDecl>(DRE->getDecl()))
return true;
if (Request.shouldHaveAdjoint(cast<VarDecl>(DRE->getDecl())))
return false;
return true;
}
} analyzer(m_DiffReq);
if (analyzer.isVariedE(arg)) {
allArgsAreConstantLiterals = false;
break;
}
Expand Down

0 comments on commit 7061c34

Please sign in to comment.