Skip to content

Commit 5b6437f

Browse files
committed
Fix a memory leak in RRCM.
Allow destructors of SmallVectors in BlockState be called when BumpPtrAllocator is destroyed
1 parent 920410f commit 5b6437f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/SILOptimizer/Transforms/RetainReleaseCodeMotion.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class CodeMotionContext {
189189
bool MultiIteration;
190190

191191
/// The allocator we are currently using.
192-
llvm::BumpPtrAllocator &BPA;
192+
llvm::SpecificBumpPtrAllocator<BlockState> &BPA;
193193

194194
/// Current function we are analyzing.
195195
SILFunction *F;
@@ -246,7 +246,7 @@ class CodeMotionContext {
246246

247247
public:
248248
/// Constructor.
249-
CodeMotionContext(llvm::BumpPtrAllocator &BPA, SILFunction *F,
249+
CodeMotionContext(llvm::SpecificBumpPtrAllocator<BlockState> &BPA, SILFunction *F,
250250
PostOrderFunctionInfo *PO, AliasAnalysis *AA,
251251
RCIdentityFunctionInfo *RCFI)
252252
: MultiIteration(true), BPA(BPA), F(F), PO(PO), AA(AA), RCFI(RCFI) {}
@@ -365,9 +365,9 @@ class RetainCodeMotionContext : public CodeMotionContext {
365365

366366
public:
367367
/// Constructor.
368-
RetainCodeMotionContext(llvm::BumpPtrAllocator &BPA, SILFunction *F,
369-
PostOrderFunctionInfo *PO, AliasAnalysis *AA,
370-
RCIdentityFunctionInfo *RCFI)
368+
RetainCodeMotionContext(llvm::SpecificBumpPtrAllocator<BlockState> &BPA,
369+
SILFunction *F, PostOrderFunctionInfo *PO,
370+
AliasAnalysis *AA, RCIdentityFunctionInfo *RCFI)
371371
: CodeMotionContext(BPA, F, PO, AA, RCFI) {
372372
MultiIteration = requireIteration();
373373
}
@@ -437,7 +437,7 @@ void RetainCodeMotionContext::initializeCodeMotionDataFlow() {
437437

438438
// Initialize all the data flow bit vector for all basic blocks.
439439
for (auto &BB : *F) {
440-
BlockStates[&BB] = new (BPA) RetainBlockState(&BB == &*F->begin(),
440+
BlockStates[&BB] = new (BPA.Allocate()) RetainBlockState(&BB == &*F->begin(),
441441
RCRootVault.size(), MultiIteration);
442442
}
443443
}
@@ -691,9 +691,9 @@ class ReleaseCodeMotionContext : public CodeMotionContext {
691691

692692
public:
693693
/// Constructor.
694-
ReleaseCodeMotionContext(llvm::BumpPtrAllocator &BPA, SILFunction *F,
695-
PostOrderFunctionInfo *PO, AliasAnalysis *AA,
696-
RCIdentityFunctionInfo *RCFI,
694+
ReleaseCodeMotionContext(llvm::SpecificBumpPtrAllocator<BlockState> &BPA,
695+
SILFunction *F, PostOrderFunctionInfo *PO,
696+
AliasAnalysis *AA, RCIdentityFunctionInfo *RCFI,
697697
bool FreezeEpilogueReleases,
698698
ConsumedArgToEpilogueReleaseMatcher &ERM)
699699
: CodeMotionContext(BPA, F, PO, AA, RCFI),
@@ -776,8 +776,8 @@ void ReleaseCodeMotionContext::initializeCodeMotionDataFlow() {
776776
if (Throw != F->end())
777777
Exits.insert(&*Throw);
778778
for (auto &BB : *F) {
779-
BlockStates[&BB] = new (BPA) ReleaseBlockState(Exits.count(&BB),
780-
RCRootVault.size(), MultiIteration);
779+
BlockStates[&BB] = new (BPA.Allocate()) ReleaseBlockState(Exits.count(&BB),
780+
RCRootVault.size(), MultiIteration);
781781
}
782782
}
783783

@@ -1054,7 +1054,7 @@ class RRCodeMotion : public SILFunctionTransform {
10541054
// to create critical edges.
10551055
bool EdgeChanged = splitAllCriticalEdges(*F, false, nullptr, nullptr);
10561056

1057-
llvm::BumpPtrAllocator BPA;
1057+
llvm::SpecificBumpPtrAllocator<BlockState> BPA;
10581058
auto *PO = PM->getAnalysis<PostOrderAnalysis>()->get(F);
10591059
auto *AA = PM->getAnalysis<AliasAnalysis>();
10601060
auto *RCFI = PM->getAnalysis<RCIdentityAnalysis>()->get(F);

0 commit comments

Comments
 (0)