[cfe-commits] r144973 - in /cfe/trunk: include/clang/Frontend/CompilerInvocation.h lib/ARCMigrate/ARCMT.cpp lib/Frontend/CompilerInvocation.cpp

Ted Kremenek kremenek at apple.com
Thu Nov 17 20:32:14 PST 2011


Author: kremenek
Date: Thu Nov 17 22:32:13 2011
New Revision: 144973

URL: http://llvm.org/viewvc/llvm-project?rev=144973&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Frontend/CompilerInvocation.h
    cfe/trunk/lib/ARCMigrate/ARCMT.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInvocation.h?rev=144973&r1=144972&r2=144973&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInvocation.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h Thu Nov 17 22:32:13 2011
@@ -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 @@
   /// 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 @@
   TargetOptions TargetOpts;
 
 public:
-  CompilerInvocation();
+  CompilerInvocation() {}
 
   /// @name Utility Methods
   /// @{
@@ -111,7 +122,7 @@
   /// \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 @@
     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;

Modified: cfe/trunk/lib/ARCMigrate/ARCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ARCMT.cpp?rev=144973&r1=144972&r2=144973&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ARCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ARCMT.cpp Thu Nov 17 22:32:13 2011
@@ -190,7 +190,6 @@
   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);

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=144973&r1=144972&r2=144973&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Nov 17 22:32:13 2011
@@ -34,12 +34,11 @@
 // 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.





More information about the cfe-commits mailing list