Skip to content

Commit

Permalink
Use CloneParmVarDecl instead of manual cloning. NFC
Browse files Browse the repository at this point in the history
Partially addresses #721
  • Loading branch information
vgvassilev committed Dec 26, 2024
1 parent 3e11004 commit a77cf9d
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions lib/Differentiator/BaseForwardModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ DerivativeAndOverload BaseForwardModeVisitor::Derive() {
m_Derivative = derivedFD;

llvm::SmallVector<ParmVarDecl*, 4> params;
ParmVarDecl* newPVD = nullptr;
const ParmVarDecl* PVD = nullptr;

// Function declaration scope
Expand All @@ -187,28 +186,18 @@ DerivativeAndOverload BaseForwardModeVisitor::Derive() {
m_Sema.PushFunctionScope();
m_Sema.PushDeclContext(getCurrentScope(), m_Derivative);

// FIXME: We should implement FunctionDecl and ParamVarDecl cloning.
for (size_t i = 0, e = FD->getNumParams(); i < e; ++i) {
PVD = FD->getParamDecl(i);
Expr* clonedPVDDefaultArg = 0;
if (PVD->hasDefaultArg())
clonedPVDDefaultArg = Clone(PVD->getDefaultArg());

newPVD = ParmVarDecl::Create(m_Context, m_Sema.CurContext, validLoc,
validLoc, PVD->getIdentifier(), PVD->getType(),
PVD->getTypeSourceInfo(),
PVD->getStorageClass(), clonedPVDDefaultArg);
auto* newPVD = CloneParmVarDecl(PVD, PVD->getIdentifier(),
/*pushOnScopeChains=*/true,
/*cloneDefaultArg=*/false);

// Make m_IndependentVar to point to the argument of the newly created
// derivedFD.
if (PVD == m_IndependentVar)
m_IndependentVar = newPVD;

params.push_back(newPVD);
// Add the args in the scope and id chain so that they could be found.
if (newPVD->getIdentifier())
m_Sema.PushOnScopeChains(newPVD, getCurrentScope(),
/*AddToContext*/ false);
}

llvm::ArrayRef<ParmVarDecl*> paramsRef =
Expand Down

0 comments on commit a77cf9d

Please sign in to comment.