Skip to content

Commit 1b5d61b

Browse files
Merge pull request #72467 from adrian-prantl/123923517
Work around a memory leak caught by the LSAN bot.
2 parents 82af38f + 0742c01 commit 1b5d61b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/IRGen/IRGenDebugInfo.cpp

+7
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,
@@ -2549,6 +2555,7 @@ void IRGenDebugInfoImpl::finalize() {
25492555
finalize(cast<llvm::MDNode>(Ty.second),
25502556
llvm::cast_or_null<llvm::DIType>(DIRefMap.lookup(UID)), UID);
25512557
}
2558+
FwdDeclTypes.clear();
25522559

25532560
// Finalize the DIBuilder.
25542561
DBuilder.finalize();

lib/IRGen/IRGenModule.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,9 @@ bool IRGenModule::finalize() {
19481948
// Finalize clang IR-generation.
19491949
finalizeClangCodeGen();
19501950

1951+
if (DebugInfo)
1952+
DebugInfo->finalize();
1953+
19511954
// If that failed, report failure up and skip the final clean-up.
19521955
if (!ClangCodeGen->GetModule())
19531956
return false;
@@ -1956,8 +1959,6 @@ bool IRGenModule::finalize() {
19561959
emitAutolinkInfo();
19571960
emitGlobalLists();
19581961
emitUsedConditionals();
1959-
if (DebugInfo)
1960-
DebugInfo->finalize();
19611962
cleanupClangCodeGenMetadata();
19621963

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

0 commit comments

Comments
 (0)