From ec2a59284252a5fba9cf7d6738f2fad087a05711 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Mon, 20 Jul 2026 12:51:15 +0000 Subject: [PATCH] Remove the unused StmtClone clone mapping. NFC StmtCloneMapping recorded, for each cloned Stmt and VarDecl, the original it came from. Nothing ever read either map, and no caller passed a mapping in the first place -- the sole StmtClone is constructed without one -- so m_OriginalToClonedStmts was permanently null and both writes were dead. Drop the struct, the member, the typedefs and the two writes. Cloning that must remap references to its clones does so through m_DeclReplacements, which the callers already maintain. --- include/clad/Differentiator/StmtClone.h | 22 ++-------------------- lib/Differentiator/StmtClone.cpp | 5 +---- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/include/clad/Differentiator/StmtClone.h b/include/clad/Differentiator/StmtClone.h index cf8529723..5c0099622 100644 --- a/include/clad/Differentiator/StmtClone.h +++ b/include/clad/Differentiator/StmtClone.h @@ -28,19 +28,11 @@ namespace clang { namespace clad { namespace utils { - struct StmtCloneMapping; - class StmtClone : public clang::StmtVisitor { public: - // first: original stmt, second: appropriate cloned stmt - typedef llvm::DenseMap StmtMapping; - typedef llvm::DenseMap DeclMapping; - typedef StmtCloneMapping Mapping; - private: clang::Sema& m_Sema; clang::ASTContext& Ctx; - Mapping* m_OriginalToClonedStmts; // While cloning a PseudoObjectExpr, maps each original OpaqueValueExpr to // its clone so the syntactic form and the semantic expressions reference // the same fresh OVE (null outside such a clone). See @@ -52,8 +44,8 @@ namespace utils { clang::VarDecl* CloneDeclOrNull(clang::VarDecl* Node); public: - StmtClone(clang::Sema& sema, clang::ASTContext& ctx, Mapping* originalToClonedStmts = 0) - : m_Sema(sema), Ctx(ctx), m_OriginalToClonedStmts(originalToClonedStmts) {} + StmtClone(clang::Sema& sema, clang::ASTContext& ctx) + : m_Sema(sema), Ctx(ctx) {} template StmtTy* Clone(const StmtTy* S); @@ -141,22 +133,12 @@ namespace utils { clang::Stmt* VisitStmt(clang::Stmt*); }; - // Not a StmtClone member class to make it forwardable: - struct StmtCloneMapping { - StmtClone::StmtMapping m_StmtMapping; - StmtClone::DeclMapping m_DeclMapping; - }; - template StmtTy* StmtClone::Clone(const StmtTy* S) { if (!S) return 0; clang::Stmt* clonedStmt = Visit(const_cast(S)); - - if (m_OriginalToClonedStmts) - m_OriginalToClonedStmts->m_StmtMapping[S] = clonedStmt; - return static_cast(clonedStmt); } diff --git a/lib/Differentiator/StmtClone.cpp b/lib/Differentiator/StmtClone.cpp index 98e69e74d..d81b24c23 100644 --- a/lib/Differentiator/StmtClone.cpp +++ b/lib/Differentiator/StmtClone.cpp @@ -614,10 +614,7 @@ Decl* StmtClone::CloneDecl(Decl* Node) { if (VD->getInit()) m_Sema.AddInitializerToDecl(cloned_Decl, Clone(VD->getInit()), VD->isDirectInit()); cloned_Decl->setTSCSpec(VD->getTSCSpec()); - //cloned_Decl->setDeclaredInCondition(VD->isDeclaredInCondition()); - if (m_OriginalToClonedStmts != 0) - m_OriginalToClonedStmts->m_DeclMapping[VD] = cloned_Decl; - + // cloned_Decl->setDeclaredInCondition(VD->isDeclaredInCondition()); return cloned_Decl; } assert(0 && "other decl clones aren't supported");