diff options
| author | Nico Weber <nicolasweber@gmx.de> | 2014-05-08 04:26:47 +0000 |
|---|---|---|
| committer | Nico Weber <nicolasweber@gmx.de> | 2014-05-08 04:26:47 +0000 |
| commit | d8758315cabbfdea5caa3e25531012d035838129 (patch) | |
| tree | 48a22e35397a92f625dfc3b7f4d62f75e8d41bb8 /lib/Frontend/CompilerInstance.cpp | |
| parent | e81307a78e7395d512cdea0a59ff7937ac8ebe63 (diff) | |
| download | clang-d8758315cabbfdea5caa3e25531012d035838129.tar.gz clang-d8758315cabbfdea5caa3e25531012d035838129.tar.bz2 clang-d8758315cabbfdea5caa3e25531012d035838129.tar.xz | |
Let ASTReader optionally delete its ASTDeserializationListener.
Use this to fix the leak of DeserializedDeclsDumper and DeserializedDeclsChecker
in FrontendAction (found by LSan), PR19560.
The "delete this" bool is necessary because both PCHGenerator and ASTUnit
return the same object from both getDeserializationListener() and
getASTMutationListener(), so ASTReader can't just have a unique_ptr.
It's also not possible to just let FrontendAction (or CompilerInstance) own
these listeners due to lifetime issues (see comments on PR19560).
Finally, ASTDeserializationListener can't easily be refcounted, since several of
the current listeners are allocated on the stack.
Having this bool isn't ideal, but it's a pattern that's used in other places in
the codebase too, and it seems better than leaking.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208277 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/CompilerInstance.cpp')
| -rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 4a75186d97..da0ca468cd 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -307,33 +307,25 @@ void CompilerInstance::createASTContext() { // ExternalASTSource -void CompilerInstance::createPCHExternalASTSource(StringRef Path, - bool DisablePCHValidation, - bool AllowPCHWithCompilerErrors, - void *DeserializationListener){ +void CompilerInstance::createPCHExternalASTSource( + StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, + void *DeserializationListener, bool OwnDeserializationListener) { IntrusiveRefCntPtr<ExternalASTSource> Source; bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0; - Source = createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot, - DisablePCHValidation, - AllowPCHWithCompilerErrors, - getPreprocessor(), getASTContext(), - DeserializationListener, - Preamble, - getFrontendOpts().UseGlobalModuleIndex); + Source = createPCHExternalASTSource( + Path, getHeaderSearchOpts().Sysroot, DisablePCHValidation, + AllowPCHWithCompilerErrors, getPreprocessor(), getASTContext(), + DeserializationListener, OwnDeserializationListener, Preamble, + getFrontendOpts().UseGlobalModuleIndex); ModuleManager = static_cast<ASTReader*>(Source.getPtr()); getASTContext().setExternalSource(Source); } -ExternalASTSource * -CompilerInstance::createPCHExternalASTSource(StringRef Path, - const std::string &Sysroot, - bool DisablePCHValidation, - bool AllowPCHWithCompilerErrors, - Preprocessor &PP, - ASTContext &Context, - void *DeserializationListener, - bool Preamble, - bool UseGlobalModuleIndex) { +ExternalASTSource *CompilerInstance::createPCHExternalASTSource( + StringRef Path, const std::string &Sysroot, bool DisablePCHValidation, + bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context, + void *DeserializationListener, bool OwnDeserializationListener, + bool Preamble, bool UseGlobalModuleIndex) { HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); std::unique_ptr<ASTReader> Reader; @@ -346,7 +338,8 @@ CompilerInstance::createPCHExternalASTSource(StringRef Path, UseGlobalModuleIndex)); Reader->setDeserializationListener( - static_cast<ASTDeserializationListener *>(DeserializationListener)); + static_cast<ASTDeserializationListener *>(DeserializationListener), + /*TakeOwnership=*/OwnDeserializationListener); switch (Reader->ReadAST(Path, Preamble ? serialization::MK_Preamble : serialization::MK_PCH, |
