[clang] [clang] Introduce copy-on-write `CompilerInvocation` (PR #65412)

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 7 08:30:33 PDT 2023


================
@@ -94,47 +96,37 @@ class CompilerInvocationRefBase {
   /// Options controlling the static analyzer.
   AnalyzerOptionsRef AnalyzerOpts;
 
-  CompilerInvocationRefBase();
-  CompilerInvocationRefBase(const CompilerInvocationRefBase &X);
-  CompilerInvocationRefBase(CompilerInvocationRefBase &&X);
-  CompilerInvocationRefBase &operator=(CompilerInvocationRefBase X);
-  CompilerInvocationRefBase &operator=(CompilerInvocationRefBase &&X);
-  ~CompilerInvocationRefBase();
+  struct ShallowCopy {};
+  struct DeepCopy {};
 
-  LangOptions &getLangOpts() { return *LangOpts; }
-  const LangOptions &getLangOpts() const { return *LangOpts; }
+  RefBase();
 
-  TargetOptions &getTargetOpts() { return *TargetOpts.get(); }
-  const TargetOptions &getTargetOpts() const { return *TargetOpts.get(); }
+  RefBase(const RefBase &X, DeepCopy);
+  RefBase(const RefBase &X, ShallowCopy);
+  RefBase(const RefBase &) = delete;
 
-  DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; }
+  RefBase &assign(const RefBase &X, DeepCopy);
+  RefBase &assign(const RefBase &X, ShallowCopy);
+  RefBase &operator=(const RefBase &) = delete;
 
-  HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; }
+  RefBase(RefBase &&);
+  RefBase &operator=(RefBase &&);
 
-  const HeaderSearchOptions &getHeaderSearchOpts() const {
-    return *HeaderSearchOpts;
-  }
+  ~RefBase();
 
-  std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
-    return HeaderSearchOpts;
-  }
-
-  std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
-    return PreprocessorOpts;
-  }
-
-  PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; }
-
-  const PreprocessorOptions &getPreprocessorOpts() const {
-    return *PreprocessorOpts;
-  }
-
-  AnalyzerOptions &getAnalyzerOpts() { return *AnalyzerOpts; }
+public:
+  // clang-format off
----------------
benlangmuir wrote:

There seems to be several formatting-off regions here; is this to cheat the length limit? I've never seen formatting disabled like this unless there's a really strong reason.

https://github.com/llvm/llvm-project/pull/65412


More information about the cfe-commits mailing list