diff options
author | Kazu Hirata <kazu@google.com> | 2025-05-22 12:44:20 -0700 |
---|---|---|
committer | Kazu Hirata <kazu@google.com> | 2025-05-22 12:44:20 -0700 |
commit | e2a885537f11f8d9ced1c80c2c90069ab5adeb1d (patch) | |
tree | d838fa124762f02c1b2ce921f667beb29acfee7b /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | e23a6921b47d2cfb4d27289149079e9d77aa0560 (diff) | |
download | llvm-e2a885537f11f8d9ced1c80c2c90069ab5adeb1d.zip llvm-e2a885537f11f8d9ced1c80c2c90069ab5adeb1d.tar.gz llvm-e2a885537f11f8d9ced1c80c2c90069ab5adeb1d.tar.bz2 |
Revert "[clang] Remove intrusive reference count from `DiagnosticOptions` (#139584)"
This reverts commit 9e306ad4600c4d3392c194a8be88919ee758425c.
Multiple builtbot failures have been reported:
https://github.com/llvm/llvm-project/pull/139584
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 9c33910..3c23073 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -125,14 +125,21 @@ static Expected<std::optional<uint32_t>> parseToleranceOption(StringRef Arg) { // Initialization. //===----------------------------------------------------------------------===// +namespace { template <class T> std::shared_ptr<T> make_shared_copy(const T &X) { return std::make_shared<T>(X); } +template <class T> +llvm::IntrusiveRefCntPtr<T> makeIntrusiveRefCntCopy(const T &X) { + return llvm::makeIntrusiveRefCnt<T>(X); +} +} // namespace + CompilerInvocationBase::CompilerInvocationBase() : LangOpts(std::make_shared<LangOptions>()), TargetOpts(std::make_shared<TargetOptions>()), - DiagnosticOpts(std::make_shared<DiagnosticOptions>()), + DiagnosticOpts(llvm::makeIntrusiveRefCnt<DiagnosticOptions>()), HSOpts(std::make_shared<HeaderSearchOptions>()), PPOpts(std::make_shared<PreprocessorOptions>()), AnalyzerOpts(std::make_shared<AnalyzerOptions>()), @@ -149,7 +156,7 @@ CompilerInvocationBase::deep_copy_assign(const CompilerInvocationBase &X) { if (this != &X) { LangOpts = make_shared_copy(X.getLangOpts()); TargetOpts = make_shared_copy(X.getTargetOpts()); - DiagnosticOpts = make_shared_copy(X.getDiagnosticOpts()); + DiagnosticOpts = makeIntrusiveRefCntCopy(X.getDiagnosticOpts()); HSOpts = make_shared_copy(X.getHeaderSearchOpts()); PPOpts = make_shared_copy(X.getPreprocessorOpts()); AnalyzerOpts = make_shared_copy(X.getAnalyzerOpts()); @@ -195,6 +202,7 @@ CompilerInvocation::operator=(const CowCompilerInvocation &X) { return *this; } +namespace { template <typename T> T &ensureOwned(std::shared_ptr<T> &Storage) { if (Storage.use_count() > 1) @@ -202,6 +210,14 @@ T &ensureOwned(std::shared_ptr<T> &Storage) { return *Storage; } +template <typename T> +T &ensureOwned(llvm::IntrusiveRefCntPtr<T> &Storage) { + if (Storage.useCount() > 1) + Storage = llvm::makeIntrusiveRefCnt<T>(*Storage); + return *Storage; +} +} // namespace + LangOptions &CowCompilerInvocation::getMutLangOpts() { return ensureOwned(LangOpts); } @@ -828,8 +844,7 @@ static bool RoundTrip(ParseFn Parse, GenerateFn Generate, }; // Setup a dummy DiagnosticsEngine. - DiagnosticOptions DummyDiagOpts; - DiagnosticsEngine DummyDiags(new DiagnosticIDs(), DummyDiagOpts); + DiagnosticsEngine DummyDiags(new DiagnosticIDs(), new DiagnosticOptions()); DummyDiags.setClient(new TextDiagnosticBuffer()); // Run the first parse on the original arguments with the dummy invocation and @@ -2648,11 +2663,9 @@ clang::CreateAndPopulateDiagOpts(ArrayRef<const char *> Argv) { bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, DiagnosticsEngine *Diags, bool DefaultDiagColor) { - std::optional<DiagnosticOptions> IgnoringDiagOpts; std::optional<DiagnosticsEngine> IgnoringDiags; if (!Diags) { - IgnoringDiagOpts.emplace(); - IgnoringDiags.emplace(new DiagnosticIDs(), *IgnoringDiagOpts, + IgnoringDiags.emplace(new DiagnosticIDs(), new DiagnosticOptions(), new IgnoringDiagConsumer()); Diags = &*IgnoringDiags; } |