summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-02-27 04:11:59 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-02-27 04:11:59 +0000
commit1b7ed91e44a8fdcb3217077204d60e7fc8d4561f (patch)
tree22268eb650ebd65e801631b863d68ea4a3d6bd74 /clang/lib/Frontend/CompilerInstance.cpp
parent08301dee468848e405d2a9c2ca08ad8af042be52 (diff)
downloadbcm5719-llvm-1b7ed91e44a8fdcb3217077204d60e7fc8d4561f.tar.gz
bcm5719-llvm-1b7ed91e44a8fdcb3217077204d60e7fc8d4561f.zip
[ASTUnit] Fix use-after-free bug in ASTUnit::getMainBufferWithPrecompiledPreamble().
With r197755 we started reading the contents of buffer file entries, but the buffers may point to ASTReader blobs that have been disposed. Fix this by having the CompilerInstance object keep a reference to the ASTReader as well as having the ASTContext keep reference to the ExternalASTSource. This was very difficult to construct a test case for. rdar://16149782 llvm-svn: 202346
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 3fe8f0e82f7..cdc4b64af77 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -104,6 +104,13 @@ void CompilerInstance::setASTConsumer(ASTConsumer *Value) {
void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) {
CompletionConsumer.reset(Value);
}
+
+IntrusiveRefCntPtr<ASTReader> CompilerInstance::getModuleManager() const {
+ return ModuleManager;
+}
+void CompilerInstance::setModuleManager(IntrusiveRefCntPtr<ASTReader> Reader) {
+ ModuleManager = Reader;
+}
// Diagnostics
static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
@@ -301,16 +308,16 @@ void CompilerInstance::createPCHExternalASTSource(StringRef Path,
bool DisablePCHValidation,
bool AllowPCHWithCompilerErrors,
void *DeserializationListener){
- OwningPtr<ExternalASTSource> Source;
+ IntrusiveRefCntPtr<ExternalASTSource> Source;
bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
- Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
+ Source = createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
DisablePCHValidation,
AllowPCHWithCompilerErrors,
getPreprocessor(), getASTContext(),
DeserializationListener,
Preamble,
- getFrontendOpts().UseGlobalModuleIndex));
- ModuleManager = static_cast<ASTReader*>(Source.get());
+ getFrontendOpts().UseGlobalModuleIndex);
+ ModuleManager = static_cast<ASTReader*>(Source.getPtr());
getASTContext().setExternalSource(Source);
}
@@ -1176,9 +1183,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
getASTContext().setASTMutationListener(
getASTConsumer().GetASTMutationListener());
}
- OwningPtr<ExternalASTSource> Source;
- Source.reset(ModuleManager);
- getASTContext().setExternalSource(Source);
+ getASTContext().setExternalSource(ModuleManager);
if (hasSema())
ModuleManager->InitializeSema(getSema());
if (hasASTConsumer())
OpenPOWER on IntegriCloud