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 | d3b74d9ca4f239a7a90ad193378c494306c57352 (patch) | |
tree | 65d677835cc2b3e9625285be0f165d5b6e9e8a65 /include/clang/Frontend/CompilerInvocation.h | |
parent | d04a982d3472d98e58f58dfc327ca11e236980f5 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144930 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Frontend/CompilerInvocation.h')
-rw-r--r-- | include/clang/Frontend/CompilerInvocation.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/include/clang/Frontend/CompilerInvocation.h b/include/clang/Frontend/CompilerInvocation.h index 47c70311dd..10cb4bc935 100644 --- a/include/clang/Frontend/CompilerInvocation.h +++ b/include/clang/Frontend/CompilerInvocation.h @@ -61,7 +61,7 @@ class CompilerInvocation : public llvm::RefCountedBase<CompilerInvocation> { HeaderSearchOptions HeaderSearchOpts; /// Options controlling the language variant. - LangOptions LangOpts; + llvm::IntrusiveRefCntPtr<LangOptions> LangOpts; /// Options controlling the preprocessor (aside from #include handling). PreprocessorOptions PreprocessorOpts; @@ -73,7 +73,7 @@ class CompilerInvocation : public llvm::RefCountedBase<CompilerInvocation> { TargetOptions TargetOpts; public: - CompilerInvocation() {} + CompilerInvocation(); /// @name Utility Methods /// @{ @@ -111,7 +111,7 @@ public: /// \param LangStd - The input language standard. void setLangDefaults(InputKind IK, LangStandard::Kind LangStd = LangStandard::lang_unspecified) { - setLangDefaults(LangOpts, IK, LangStd); + setLangDefaults(*LangOpts, IK, LangStd); } /// setLangDefaults - Set language defaults for the given input language and @@ -166,8 +166,10 @@ public: return FrontendOpts; } - LangOptions &getLangOpts() { return LangOpts; } - const LangOptions &getLangOpts() const { return LangOpts; } + LangOptions *getLangOpts() { return LangOpts.getPtr(); } + const LangOptions *getLangOpts() const { return LangOpts.getPtr(); } + + void setLangOpts(LangOptions *LangOpts); PreprocessorOptions &getPreprocessorOpts() { return PreprocessorOpts; } const PreprocessorOptions &getPreprocessorOpts() const { |