aboutsummaryrefslogtreecommitdiff
path: root/clang/tools/libclang/CIndexCodeCompletion.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2025-05-22 12:33:52 -0700
committerGitHub <noreply@github.com>2025-05-22 12:33:52 -0700
commit9e306ad4600c4d3392c194a8be88919ee758425c (patch)
treef8b15171e92d056e9006bcbe36d534a9d73155d9 /clang/tools/libclang/CIndexCodeCompletion.cpp
parent2b8bff6f66fd90ac658d0ae0d7f9a83ffadfd77f (diff)
downloadllvm-9e306ad4600c4d3392c194a8be88919ee758425c.zip
llvm-9e306ad4600c4d3392c194a8be88919ee758425c.tar.gz
llvm-9e306ad4600c4d3392c194a8be88919ee758425c.tar.bz2
[clang] Remove intrusive reference count from `DiagnosticOptions` (#139584)
The `DiagnosticOptions` class is currently intrusively reference-counted, which makes reasoning about its lifetime very difficult in some cases. For example, `CompilerInvocation` owns the `DiagnosticOptions` instance (wrapped in `llvm::IntrusiveRefCntPtr`) and only exposes an accessor returning `DiagnosticOptions &`. One would think this gives `CompilerInvocation` exclusive ownership of the object, but that's not the case: ```c++ void shareOwnership(CompilerInvocation &CI) { llvm::IntrusiveRefCntPtr<DiagnosticOptions> CoOwner = &CI.getDiagnosticOptions(); // ... } ``` This is a perfectly valid pattern that is being actually used in the codebase. I would like to ensure the ownership of `DiagnosticOptions` by `CompilerInvocation` is guaranteed to be exclusive. This can be leveraged for a copy-on-write optimization later on. This PR changes usages of `DiagnosticOptions` across `clang`, `clang-tools-extra` and `lldb` to not be intrusively reference-counted.
Diffstat (limited to 'clang/tools/libclang/CIndexCodeCompletion.cpp')
-rw-r--r--clang/tools/libclang/CIndexCodeCompletion.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/clang/tools/libclang/CIndexCodeCompletion.cpp b/clang/tools/libclang/CIndexCodeCompletion.cpp
index 850c004..8f6729b 100644
--- a/clang/tools/libclang/CIndexCodeCompletion.cpp
+++ b/clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -256,8 +256,8 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults {
/// Allocated API-exposed wrappters for Diagnostics.
SmallVector<std::unique_ptr<CXStoredDiagnostic>, 8> DiagnosticsWrappers;
- IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
-
+ DiagnosticOptions DiagOpts;
+
/// Diag object
IntrusiveRefCntPtr<DiagnosticsEngine> Diag;
@@ -356,9 +356,9 @@ static std::atomic<unsigned> CodeCompletionResultObjects;
AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults(
IntrusiveRefCntPtr<FileManager> FileMgr)
- : CXCodeCompleteResults(), DiagOpts(new DiagnosticOptions),
+ : CXCodeCompleteResults(),
Diag(new DiagnosticsEngine(
- IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts)),
+ IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), DiagOpts)),
FileMgr(std::move(FileMgr)),
SourceMgr(new SourceManager(*Diag, *this->FileMgr)),
CodeCompletionAllocator(
@@ -369,7 +369,7 @@ AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults(
fprintf(stderr, "+++ %u completion results\n",
++CodeCompletionResultObjects);
}
-
+
AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() {
delete [] Results;