diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-11-18 04:32:13 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-11-18 04:32:13 +0000 |
commit | 8a0c5c2ec5c5496cfb01d2c86bd50991866a7356 (patch) | |
tree | 74922c6dc1fe51083207be0ef3884f31f7c3ea7b | |
parent | 5a1ac89b244940a0337ea7ae7dc371e2a9bf7c50 (diff) |
Refine placement of LangOptions object in CompilerInvocation by adding a new baseclass CompilerInvocationBase with a custom copy constructor. This ensures that whenever the CompilerInvocation object's copy constructor is used we always clone the LangOptions object.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144973 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Frontend/CompilerInvocation.h | 28 | ||||
-rw-r--r-- | lib/ARCMigrate/ARCMT.cpp | 1 | ||||
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 7 |
3 files changed, 20 insertions, 16 deletions
diff --git a/include/clang/Frontend/CompilerInvocation.h b/include/clang/Frontend/CompilerInvocation.h index 10cb4bc935..bbefdb662d 100644 --- a/include/clang/Frontend/CompilerInvocation.h +++ b/include/clang/Frontend/CompilerInvocation.h @@ -30,15 +30,29 @@ namespace clang { +class CompilerInvocation; class DiagnosticsEngine; + +class CompilerInvocationBase : public llvm::RefCountedBase<CompilerInvocation> { +protected: + /// Options controlling the language variant. + llvm::IntrusiveRefCntPtr<LangOptions> LangOpts; +public: + CompilerInvocationBase(); + CompilerInvocationBase(const CompilerInvocationBase &X); + + LangOptions *getLangOpts() { return LangOpts.getPtr(); } + const LangOptions *getLangOpts() const { return LangOpts.getPtr(); } +}; + /// CompilerInvocation - Helper class for holding the data necessary to invoke /// the compiler. /// /// This class is designed to represent an abstract "invocation" of the /// compiler, including data such as the include paths, the code generation /// options, the warning flags, and so on. -class CompilerInvocation : public llvm::RefCountedBase<CompilerInvocation> { +class CompilerInvocation : public CompilerInvocationBase { /// Options controlling the static analyzer. AnalyzerOptions AnalyzerOpts; @@ -60,9 +74,6 @@ class CompilerInvocation : public llvm::RefCountedBase<CompilerInvocation> { /// Options controlling the #include directive. HeaderSearchOptions HeaderSearchOpts; - /// Options controlling the language variant. - llvm::IntrusiveRefCntPtr<LangOptions> LangOpts; - /// Options controlling the preprocessor (aside from #include handling). PreprocessorOptions PreprocessorOpts; @@ -73,7 +84,7 @@ class CompilerInvocation : public llvm::RefCountedBase<CompilerInvocation> { TargetOptions TargetOpts; public: - CompilerInvocation(); + CompilerInvocation() {} /// @name Utility Methods /// @{ @@ -111,7 +122,7 @@ public: /// \param LangStd - The input language standard. void setLangDefaults(InputKind IK, LangStandard::Kind LangStd = LangStandard::lang_unspecified) { - setLangDefaults(*LangOpts, IK, LangStd); + setLangDefaults(*getLangOpts(), IK, LangStd); } /// setLangDefaults - Set language defaults for the given input language and @@ -166,11 +177,6 @@ public: return FrontendOpts; } - LangOptions *getLangOpts() { return LangOpts.getPtr(); } - const LangOptions *getLangOpts() const { return LangOpts.getPtr(); } - - void setLangOpts(LangOptions *LangOpts); - PreprocessorOptions &getPreprocessorOpts() { return PreprocessorOpts; } const PreprocessorOptions &getPreprocessorOpts() const { return PreprocessorOpts; diff --git a/lib/ARCMigrate/ARCMT.cpp b/lib/ARCMigrate/ARCMT.cpp index 06bc6b8c04..9985160468 100644 --- a/lib/ARCMigrate/ARCMT.cpp +++ b/lib/ARCMigrate/ARCMT.cpp @@ -190,7 +190,6 @@ createInvocationForMigration(CompilerInvocation &origCI) { CInvok->getPreprocessorOpts().ImplicitPTHInclude = std::string(); std::string define = getARCMTMacroName(); define += '='; - CInvok->setLangOpts(new LangOptions(*CInvok->getLangOpts())); CInvok->getPreprocessorOpts().addMacroDef(define); CInvok->getLangOpts()->ObjCAutoRefCount = true; CInvok->getLangOpts()->setGC(LangOptions::NonGC); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 13be408141..738facf069 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -34,12 +34,11 @@ using namespace clang; // Initialization. //===----------------------------------------------------------------------===// -CompilerInvocation::CompilerInvocation() +CompilerInvocationBase::CompilerInvocationBase() : LangOpts(new LangOptions()) {} -void CompilerInvocation::setLangOpts(LangOptions *LOpts) { - LangOpts = LOpts; -} +CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X) + : LangOpts(new LangOptions(*X.getLangOpts())) {} //===----------------------------------------------------------------------===// // Utility functions. |