From 13e1a2cb2246dc5e9a4afcdacabed4d43154ec3f Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Thu, 22 May 2025 12:51:28 -0700 Subject: Reapply "[clang] Remove intrusive reference count from `DiagnosticOptions` (#139584)" This reverts commit e2a885537f11f8d9ced1c80c2c90069ab5adeb1d. Build failures were fixed right away and reverting the original commit without the fixes breaks the build again. --- clang/lib/Frontend/CompilerInvocation.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 3c23073..9c33910 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -125,21 +125,14 @@ static Expected> parseToleranceOption(StringRef Arg) { // Initialization. //===----------------------------------------------------------------------===// -namespace { template std::shared_ptr make_shared_copy(const T &X) { return std::make_shared(X); } -template -llvm::IntrusiveRefCntPtr makeIntrusiveRefCntCopy(const T &X) { - return llvm::makeIntrusiveRefCnt(X); -} -} // namespace - CompilerInvocationBase::CompilerInvocationBase() : LangOpts(std::make_shared()), TargetOpts(std::make_shared()), - DiagnosticOpts(llvm::makeIntrusiveRefCnt()), + DiagnosticOpts(std::make_shared()), HSOpts(std::make_shared()), PPOpts(std::make_shared()), AnalyzerOpts(std::make_shared()), @@ -156,7 +149,7 @@ CompilerInvocationBase::deep_copy_assign(const CompilerInvocationBase &X) { if (this != &X) { LangOpts = make_shared_copy(X.getLangOpts()); TargetOpts = make_shared_copy(X.getTargetOpts()); - DiagnosticOpts = makeIntrusiveRefCntCopy(X.getDiagnosticOpts()); + DiagnosticOpts = make_shared_copy(X.getDiagnosticOpts()); HSOpts = make_shared_copy(X.getHeaderSearchOpts()); PPOpts = make_shared_copy(X.getPreprocessorOpts()); AnalyzerOpts = make_shared_copy(X.getAnalyzerOpts()); @@ -202,7 +195,6 @@ CompilerInvocation::operator=(const CowCompilerInvocation &X) { return *this; } -namespace { template T &ensureOwned(std::shared_ptr &Storage) { if (Storage.use_count() > 1) @@ -210,14 +202,6 @@ T &ensureOwned(std::shared_ptr &Storage) { return *Storage; } -template -T &ensureOwned(llvm::IntrusiveRefCntPtr &Storage) { - if (Storage.useCount() > 1) - Storage = llvm::makeIntrusiveRefCnt(*Storage); - return *Storage; -} -} // namespace - LangOptions &CowCompilerInvocation::getMutLangOpts() { return ensureOwned(LangOpts); } @@ -844,7 +828,8 @@ static bool RoundTrip(ParseFn Parse, GenerateFn Generate, }; // Setup a dummy DiagnosticsEngine. - DiagnosticsEngine DummyDiags(new DiagnosticIDs(), new DiagnosticOptions()); + DiagnosticOptions DummyDiagOpts; + DiagnosticsEngine DummyDiags(new DiagnosticIDs(), DummyDiagOpts); DummyDiags.setClient(new TextDiagnosticBuffer()); // Run the first parse on the original arguments with the dummy invocation and @@ -2663,9 +2648,11 @@ clang::CreateAndPopulateDiagOpts(ArrayRef Argv) { bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, DiagnosticsEngine *Diags, bool DefaultDiagColor) { + std::optional IgnoringDiagOpts; std::optional IgnoringDiags; if (!Diags) { - IgnoringDiags.emplace(new DiagnosticIDs(), new DiagnosticOptions(), + IgnoringDiagOpts.emplace(); + IgnoringDiags.emplace(new DiagnosticIDs(), *IgnoringDiagOpts, new IgnoringDiagConsumer()); Diags = &*IgnoringDiags; } -- cgit v1.1