diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-11-17 23:01:24 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-11-17 23:01:24 +0000 |
commit | 8cf47df72f999b0adaeded4b2190978bc992ffc5 (patch) | |
tree | bab5bff7943e840647820feb4e46f76c89f2fadd /clang/lib/Frontend/ASTUnit.cpp | |
parent | 250476021f5ab554cc4eb245a6ccfe7bc1236281 (diff) | |
download | bcm5719-llvm-8cf47df72f999b0adaeded4b2190978bc992ffc5.tar.gz bcm5719-llvm-8cf47df72f999b0adaeded4b2190978bc992ffc5.zip |
Make 'LangOptions' in CompilerInvocation a heap-allocated, reference counted object. I discovered that llvm::RefCountedBase<T> has
a bug where the reference count is copied in the copy constructor, which means that there were cases when the CompilerInvocation
objects created by ASTUnit were actually leaked. When I fixed that bug locally, it showed that a whole bunch of code assumed
that the LangOptions object that was part of CompilerInvocation was still alive. By making it heap-allocated and reference counted,
we can keep it around after the CompilerInvocation object goes away.
As part of this change, change CompilerInvocation:getLangOptions() to return a pointer, acting as another clue that this
object may outlive the CompilerInvocation object.
This commit doesn't fix the CompilerInvocation leak itself. That will come when I commit the fix to llvm::RefCountedBase<T> to
mainline LLVM.
llvm-svn: 144930
Diffstat (limited to 'clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index e2544027b5a..c59f2d16d28 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1041,6 +1041,7 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) { // Configure the various subsystems. // FIXME: Should we retain the previous file manager? + LangOpts = &Clang->getLangOpts(); FileSystemOpts = Clang->getFileSystemOpts(); FileMgr = new FileManager(FileSystemOpts); SourceMgr = new SourceManager(getDiagnostics(), *FileMgr); @@ -1247,7 +1248,7 @@ ASTUnit::ComputePreamble(CompilerInvocation &Invocation, } return std::make_pair(Buffer, Lexer::ComputePreamble(Buffer, - Invocation.getLangOpts(), + *Invocation.getLangOpts(), MaxLines)); } @@ -2230,7 +2231,7 @@ void ASTUnit::CodeComplete(StringRef File, unsigned Line, unsigned Column, FrontendOpts.CodeCompletionAt.Column = Column; // Set the language options appropriately. - LangOpts = CCInvocation->getLangOpts(); + LangOpts = *CCInvocation->getLangOpts(); llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance()); |