From b00cd15d543827918f7b1659c82872776af0034d Mon Sep 17 00:00:00 2001 From: kchristin Date: Sat, 9 Nov 2024 15:20:28 +0200 Subject: [PATCH] Remove use of setNumArgsUnsafe in Clone functions --- lib/Differentiator/StmtClone.cpp | 38 ++++++++++++++------------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/Differentiator/StmtClone.cpp b/lib/Differentiator/StmtClone.cpp index 08bef1ad0..81413ba95 100644 --- a/lib/Differentiator/StmtClone.cpp +++ b/lib/Differentiator/StmtClone.cpp @@ -313,13 +313,14 @@ Stmt* StmtClone::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr* Node) { } Stmt* StmtClone::VisitCallExpr(CallExpr* Node) { + llvm::SmallVector clonedArgs; + for (Expr* arg : Node->arguments()) + clonedArgs.push_back(Clone(arg)); + CallExpr* result = clad_compat::CallExpr_Create( - Ctx, Clone(Node->getCallee()), llvm::ArrayRef(), - 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); @@ -328,13 +329,14 @@ Stmt* StmtClone::VisitCallExpr(CallExpr* Node) { } Stmt* StmtClone::VisitCUDAKernelCallExpr(CUDAKernelCallExpr* Node) { + llvm::SmallVector 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(), 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); @@ -367,11 +369,6 @@ 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); @@ -379,16 +376,15 @@ Stmt* StmtClone::VisitCXXOperatorCallExpr(CXXOperatorCallExpr* Node) { } Stmt* StmtClone::VisitCXXMemberCallExpr(CXXMemberCallExpr * Node) { + llvm::SmallVector 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);