Skip to content

Commit

Permalink
Mark variables passed by pointer/reference as varied
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Andriychuk committed Nov 18, 2024
1 parent 0bf8e21 commit e34f84b
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/Differentiator/ActivityAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,39 @@ bool VariedAnalyzer::VisitCallExpr(CallExpr* CE) {
MutableArrayRef<ParmVarDecl*> FDparam = FD->parameters();
for (std::size_t i = 0, e = CE->getNumArgs(); i != e; ++i) {
clang::Expr* par = CE->getArg(i);

QualType parType = FDparam[i]->getType();
while (parType->isPointerType())
parType = parType->getPointeeType();
if((parType->isReferenceType() || utils::isArrayOrPointerType(parType)) && !parType.isConstQualified()){
m_Marking = true;
m_Varied = true;
}

TraverseStmt(par);
m_VariedDecls.insert(FDparam[i]);

m_Marking = false;
m_Varied = false;

if(!parType.isConstQualified())
m_VariedDecls.insert(FDparam[i]);
}
}
return true;
}

bool VariedAnalyzer::VisitDeclStmt(DeclStmt* DS) {
for (Decl* D : DS->decls()) {
QualType VDTy = cast<VarDecl>(D)->getType();
if(utils::isArrayOrPointerType(VDTy)){
copyVarToCurBlock(cast<VarDecl>(D));
continue;
}
if (Expr* init = cast<VarDecl>(D)->getInit()) {
m_Varied = false;
TraverseStmt(init);
m_Marking = true;
QualType VDTy = cast<VarDecl>(D)->getType();
if (m_Varied || utils::isArrayOrPointerType(VDTy))
if (m_Varied )
copyVarToCurBlock(cast<VarDecl>(D));
m_Marking = false;
}
Expand Down

0 comments on commit e34f84b

Please sign in to comment.