Skip to content

Commit 0742c01

Browse files
committed
Work around a memory leak caught by the LSAN bot.
Fundamentally the problem here is that SILPassManager is creating an IRGenModule without calling finalize() on it under some circumstances. It would be better to fix that instead. rdar://123923517
1 parent 0f5dc13 commit 0742c01

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
204204
IRGenModule &IGM, llvm::Module &M,
205205
StringRef MainOutputFilenameForDebugInfo,
206206
StringRef PrivateDiscriminator);
207+
~IRGenDebugInfoImpl() {
208+
// FIXME: SILPassManager sometimes creates an IGM and doesn't finalize it.
209+
if (!FwdDeclTypes.empty())
210+
finalize();
211+
assert(FwdDeclTypes.empty() && "finalize() was not called");
212+
}
207213
void finalize();
208214

209215
void setCurrentLoc(IRBuilder &Builder, const SILDebugScope *DS,
@@ -2478,6 +2484,7 @@ void IRGenDebugInfoImpl::finalize() {
24782484
finalize(cast<llvm::MDNode>(Ty.second),
24792485
llvm::cast_or_null<llvm::DIType>(DIRefMap.lookup(UID)), UID);
24802486
}
2487+
FwdDeclTypes.clear();
24812488

24822489
// Finalize the DIBuilder.
24832490
DBuilder.finalize();

lib/IRGen/IRGenModule.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,9 @@ bool IRGenModule::finalize() {
19471947
// Finalize clang IR-generation.
19481948
finalizeClangCodeGen();
19491949

1950+
if (DebugInfo)
1951+
DebugInfo->finalize();
1952+
19501953
// If that failed, report failure up and skip the final clean-up.
19511954
if (!ClangCodeGen->GetModule())
19521955
return false;
@@ -1955,8 +1958,6 @@ bool IRGenModule::finalize() {
19551958
emitAutolinkInfo();
19561959
emitGlobalLists();
19571960
emitUsedConditionals();
1958-
if (DebugInfo)
1959-
DebugInfo->finalize();
19601961
cleanupClangCodeGenMetadata();
19611962

19621963
// Clean up DSOLocal & DLLImport attributes, they cannot be applied together.

0 commit comments

Comments
 (0)