Skip to content

Commit eaca60d

Browse files
authored
[clang] Hide the DiagnosticOptions pointer from CompilerInvocation (#106274)
This PR hides the reference-counter pointer that holds `DiagnosticOptions` from the public API of `CompilerInvocation`. This gives `CompilerInvocation` an exclusive control over the lifetime of this member, which will eventually be leveraged to implement a copy-on-write behavior. The only client that currently accesses that pointer is `clangd::buildPreamble()` which takes care to reset it so that it's not reset concurrently. This code is made redundant by making the reference count of `DiagnosticOptions` atomic.
1 parent 6501647 commit eaca60d

File tree

3 files changed

+2
-3
lines changed

3 files changed

+2
-3
lines changed

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
673673
// Reset references to ref-counted-ptrs before executing the callbacks, to
674674
// prevent resetting them concurrently.
675675
PreambleDiagsEngine.reset();
676-
CI.DiagnosticOpts.reset();
677676

678677
// When building the AST for the main file, we do want the function
679678
// bodies.

clang/include/clang/Basic/DiagnosticOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ inline DiagnosticLevelMask operator&(DiagnosticLevelMask LHS,
6767
raw_ostream& operator<<(raw_ostream& Out, DiagnosticLevelMask M);
6868

6969
/// Options for controlling the compiler diagnostics engine.
70-
class DiagnosticOptions : public RefCountedBase<DiagnosticOptions>{
70+
class DiagnosticOptions
71+
: public llvm::ThreadSafeRefCountedBase<DiagnosticOptions> {
7172
friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &,
7273
clang::DiagnosticsEngine *, bool);
7374

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ class CompilerInvocation : public CompilerInvocationBase {
269269
/// @{
270270
using CompilerInvocationBase::LangOpts;
271271
using CompilerInvocationBase::TargetOpts;
272-
using CompilerInvocationBase::DiagnosticOpts;
273272
std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() {
274273
return HSOpts;
275274
}

0 commit comments

Comments
 (0)