-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang] Hide the DiagnosticOptions pointer from CompilerInvocation
#106274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] Hide the DiagnosticOptions pointer from CompilerInvocation
#106274
Conversation
|
@llvm/pr-subscribers-clangd @llvm/pr-subscribers-clang-tools-extra Author: Jan Svoboda (jansvoboda11) ChangesThis PR hides the reference-counter pointer that holds The only client that currently accesses that pointer is Full diff: https://github.com/llvm/llvm-project/pull/106274.diff 3 Files Affected:
diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp
index dd13b1a9e5613d..51d478cf4efc1d 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -673,7 +673,6 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
// Reset references to ref-counted-ptrs before executing the callbacks, to
// prevent resetting them concurrently.
PreambleDiagsEngine.reset();
- CI.DiagnosticOpts.reset();
// When building the AST for the main file, we do want the function
// bodies.
diff --git a/clang/include/clang/Basic/DiagnosticOptions.h b/clang/include/clang/Basic/DiagnosticOptions.h
index 30141c2b8f4475..ea8da70e081f01 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.h
+++ b/clang/include/clang/Basic/DiagnosticOptions.h
@@ -67,7 +67,8 @@ inline DiagnosticLevelMask operator&(DiagnosticLevelMask LHS,
raw_ostream& operator<<(raw_ostream& Out, DiagnosticLevelMask M);
/// Options for controlling the compiler diagnostics engine.
-class DiagnosticOptions : public RefCountedBase<DiagnosticOptions>{
+class DiagnosticOptions
+ : public llvm::ThreadSafeRefCountedBase<DiagnosticOptions> {
friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &,
clang::DiagnosticsEngine *, bool);
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h
index 9daa0a1ecf9488..1e4d2da86c2bee 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -269,7 +269,6 @@ class CompilerInvocation : public CompilerInvocationBase {
/// @{
using CompilerInvocationBase::LangOpts;
using CompilerInvocationBase::TargetOpts;
- using CompilerInvocationBase::DiagnosticOpts;
std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() {
return HSOpts;
}
|
|
@llvm/pr-subscribers-clang Author: Jan Svoboda (jansvoboda11) ChangesThis PR hides the reference-counter pointer that holds The only client that currently accesses that pointer is Full diff: https://github.com/llvm/llvm-project/pull/106274.diff 3 Files Affected:
diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp
index dd13b1a9e5613d..51d478cf4efc1d 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -673,7 +673,6 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
// Reset references to ref-counted-ptrs before executing the callbacks, to
// prevent resetting them concurrently.
PreambleDiagsEngine.reset();
- CI.DiagnosticOpts.reset();
// When building the AST for the main file, we do want the function
// bodies.
diff --git a/clang/include/clang/Basic/DiagnosticOptions.h b/clang/include/clang/Basic/DiagnosticOptions.h
index 30141c2b8f4475..ea8da70e081f01 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.h
+++ b/clang/include/clang/Basic/DiagnosticOptions.h
@@ -67,7 +67,8 @@ inline DiagnosticLevelMask operator&(DiagnosticLevelMask LHS,
raw_ostream& operator<<(raw_ostream& Out, DiagnosticLevelMask M);
/// Options for controlling the compiler diagnostics engine.
-class DiagnosticOptions : public RefCountedBase<DiagnosticOptions>{
+class DiagnosticOptions
+ : public llvm::ThreadSafeRefCountedBase<DiagnosticOptions> {
friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &,
clang::DiagnosticsEngine *, bool);
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h
index 9daa0a1ecf9488..1e4d2da86c2bee 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -269,7 +269,6 @@ class CompilerInvocation : public CompilerInvocationBase {
/// @{
using CompilerInvocationBase::LangOpts;
using CompilerInvocationBase::TargetOpts;
- using CompilerInvocationBase::DiagnosticOpts;
std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() {
return HSOpts;
}
|
|
yes turning diagnosticoptions to be a ThreadSafeRefCountedBase pointer should ensure we have similar guarantees. so LG from clangd side, but I am not sure about implications on using thread-aware structs in core parts of clang. so it might be worthwhile to get some opinions from clang maintainers as well. |
Thanks for confirming!
Good point. @AaronBallman any thoughts? |
So long as there are sufficient comments explaining why the thread-safety is needed, I think it's okay. |
This PR hides the reference-counter pointer that holds
DiagnosticOptionsfrom the public API ofCompilerInvocation. This givesCompilerInvocationan 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 ofDiagnosticOptionsatomic.