Skip to content

Commit

Permalink
Remove use of setNumArgsUnsafe in Clone functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kchristin22 committed Nov 9, 2024
1 parent e62f640 commit b00cd15
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions lib/Differentiator/StmtClone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,14 @@ Stmt* StmtClone::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr* Node) {
}

Stmt* StmtClone::VisitCallExpr(CallExpr* Node) {
llvm::SmallVector<Expr*, 4> clonedArgs;
for (Expr* arg : Node->arguments())
clonedArgs.push_back(Clone(arg));

CallExpr* result = clad_compat::CallExpr_Create(
Ctx, Clone(Node->getCallee()), llvm::ArrayRef<Expr*>(),
CloneType(Node->getType()), Node->getValueKind(),
Ctx, Clone(Node->getCallee()), clonedArgs, CloneType(Node->getType()),
Node->getValueKind(),
Node->getRParenLoc() CLAD_COMPAT_CLANG8_CallExpr_ExtraParams);
result->setNumArgsUnsafe(Node->getNumArgs());
for (unsigned i = 0, e = Node->getNumArgs(); i < e; ++i)
result->setArg(i, Clone(Node->getArg(i)));

// Copy Value and Type dependent
clad_compat::ExprSetDeps(result, Node);
Expand All @@ -328,13 +329,14 @@ Stmt* StmtClone::VisitCallExpr(CallExpr* Node) {
}

Stmt* StmtClone::VisitCUDAKernelCallExpr(CUDAKernelCallExpr* Node) {
llvm::SmallVector<Expr*, 4> clonedArgs;
for (Expr* arg : Node->arguments())
clonedArgs.push_back(Clone(arg));

CUDAKernelCallExpr* result = clad_compat::CUDAKernelCallExpr_Create(
Ctx, Clone(Node->getCallee()), Clone(Node->getConfig()),
llvm::ArrayRef<Expr*>(), CloneType(Node->getType()), Node->getValueKind(),
Ctx, Clone(Node->getCallee()), Clone(Node->getConfig()), clonedArgs,
CloneType(Node->getType()), Node->getValueKind(),
Node->getRParenLoc() CLAD_COMPAT_CLANG8_CallExpr_ExtraParams);
result->setNumArgsUnsafe(Node->getNumArgs());
for (unsigned i = 0, e = Node->getNumArgs(); i < e; ++i)
result->setArg(i, Clone(Node->getArg(i)));

// Copy Value and Type dependent
clad_compat::ExprSetDeps(result, Node);
Expand Down Expand Up @@ -367,28 +369,22 @@ Stmt* StmtClone::VisitCXXOperatorCallExpr(CXXOperatorCallExpr* Node) {
Node->getFPFeatures()
CLAD_COMPAT_CLANG11_CXXOperatorCallExpr_Create_ExtraParamsUse);

//### result->setNumArgs(Ctx, Node->getNumArgs());
result->setNumArgsUnsafe(Node->getNumArgs());
for (unsigned i = 0, e = Node->getNumArgs(); i < e; ++i)
result->setArg(i, Clone(Node->getArg(i)));

// Copy Value and Type dependent
clad_compat::ExprSetDeps(result, Node);

return result;
}

Stmt* StmtClone::VisitCXXMemberCallExpr(CXXMemberCallExpr * Node) {
llvm::SmallVector<Expr*, 4> clonedArgs;
for (Expr* arg : Node->arguments())
clonedArgs.push_back(Clone(arg));

CXXMemberCallExpr* result = clad_compat::CXXMemberCallExpr_Create(
Ctx, Clone(Node->getCallee()), {}, CloneType(Node->getType()),
Ctx, Clone(Node->getCallee()), clonedArgs, CloneType(Node->getType()),
Node->getValueKind(),
Node->getRParenLoc()
/*FP*/ CLAD_COMPAT_CLANG12_CastExpr_GetFPO(Node));
// ### result->setNumArgs(Ctx, Node->getNumArgs());
result->setNumArgsUnsafe(Node->getNumArgs());

for (unsigned i = 0, e = Node->getNumArgs(); i < e; ++i)
result->setArg(i, Clone(Node->getArg(i)));

// Copy Value and Type dependent
clad_compat::ExprSetDeps(result, Node);
Expand Down

0 comments on commit b00cd15

Please sign in to comment.