[clang] [clang-tools-extra] [lldb] [clang] Remove intrusive reference count from `DiagnosticOptions` (PR #139584)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Wed May 14 07:50:16 PDT 2025


================
@@ -107,6 +107,7 @@ class ASTUnit {
 
 private:
   std::unique_ptr<LangOptions> LangOpts;
+  std::shared_ptr<DiagnosticOptions> DiagOpts;
----------------
jansvoboda11 wrote:

I was hoping it could be, but the situation is a bit weird. The documentation for `ASTUnit::LoadFromCommandLine()` says the `DiagnosticsEngine` parameter is expected to outlive the returned value. However, it's being passed in `IntrusiveRefCntPtr`, so the lifetime is not enforced, and of course some clients started to rely on `ASTUnit` taking shared ownership of that object. And the clients also use the `DiagnosticsEngine` object themselves after passing it to that function, so the ownership is indeed shared. And since `DiagnosticsEngine` now relies on `DiagnosticOptions` to live long enough, sharing ownership in `ASTUnit` was the best fit. Does that make sense?

In general `ASTUnit` is a big pile of lifetime hacks which I'd like to clean up one day, but today is not the day.

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


More information about the cfe-commits mailing list