Skip to content

Commit

Permalink
SymbolManager::SymbolDependencies: Use unique_ptr to simplify memory …
Browse files Browse the repository at this point in the history
…management
  • Loading branch information
dwblaikie committed Apr 29, 2020
1 parent e265f92 commit 6288292
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
16 changes: 4 additions & 12 deletions clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
Expand Up @@ -341,10 +341,6 @@ QualType SymbolRegionValue::getType() const {
return R->getValueType();
}

SymbolManager::~SymbolManager() {
llvm::DeleteContainerSeconds(SymbolDependencies);
}

bool SymbolManager::canSymbolicate(QualType T) {
T = T.getCanonicalType();

Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down

0 comments on commit 6288292

Please sign in to comment.