Author: David Blaikie Date: 2020-04-28T22:31:17-07:00 New Revision: 628829254d35bd3dfd1bff29f8afeaf464aafde9
URL: https://github.com/llvm/llvm-project/commit/628829254d35bd3dfd1bff29f8afeaf464aafde9 DIFF: https://github.com/llvm/llvm-project/commit/628829254d35bd3dfd1bff29f8afeaf464aafde9.diff LOG: SymbolManager::SymbolDependencies: Use unique_ptr to simplify memory management Added: Modified: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h clang/lib/StaticAnalyzer/Core/SymbolManager.cpp Removed: ################################################################################ diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h index d212e23da6fc..2c505995bee0 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h @@ -459,7 +459,8 @@ class SymSymExpr : public BinarySymExpr { class SymbolManager { using DataSetTy = llvm::FoldingSet<SymExpr>; - using SymbolDependTy = llvm::DenseMap<SymbolRef, SymbolRefSmallVectorTy *>; + using SymbolDependTy = + llvm::DenseMap<SymbolRef, std::unique_ptr<SymbolRefSmallVectorTy>>; DataSetTy DataSet; @@ -476,7 +477,6 @@ class SymbolManager { SymbolManager(ASTContext &ctx, BasicValueFactory &bv, llvm::BumpPtrAllocator& bpalloc) : SymbolDependencies(16), BPAlloc(bpalloc), BV(bv), Ctx(ctx) {} - ~SymbolManager(); static bool canSymbolicate(QualType T); diff --git a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp index e655aae45832..ff6cd21b09d6 100644 --- a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp @@ -341,10 +341,6 @@ QualType SymbolRegionValue::getType() const { return R->getValueType(); } -SymbolManager::~SymbolManager() { - llvm::DeleteContainerSeconds(SymbolDependencies); -} - bool SymbolManager::canSymbolicate(QualType T) { T = T.getCanonicalType(); @@ -362,13 +358,9 @@ bool SymbolManager::canSymbolicate(QualType T) { void SymbolManager::addSymbolDependency(const SymbolRef Primary, const SymbolRef Dependent) { - SymbolDependTy::iterator I = SymbolDependencies.find(Primary); - SymbolRefSmallVectorTy *dependencies = nullptr; - if (I == SymbolDependencies.end()) { - dependencies = new SymbolRefSmallVectorTy(); - SymbolDependencies[Primary] = dependencies; - } else { - dependencies = I->second; + auto &dependencies = SymbolDependencies[Primary]; + if (!dependencies) { + dependencies = std::make_unique<SymbolRefSmallVectorTy>(); } dependencies->push_back(Dependent); } @@ -378,7 +370,7 @@ const SymbolRefSmallVectorTy *SymbolManager::getDependentSymbols( SymbolDependTy::const_iterator I = SymbolDependencies.find(Primary); if (I == SymbolDependencies.end()) return nullptr; - return I->second; + return I->second.get(); } void SymbolReaper::markDependentsLive(SymbolRef sym) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits