[lldb][ClangExpressionParser] Clean up ownership of members in ClangDiagnosticManagerAdapter#167731
Merged
Michael137 merged 1 commit intollvm:mainfrom Nov 12, 2025
Conversation
…iagnosticManagerAdapter This aligns `ClangDiagnosticManagerAdapter` with how we set up the diagnostics in `ClangModulesDeclVendor`. We fixed lifetime issues around the same kind of setup here: llvm#167724 This class didn't suffer from the same lifetime issue because it used `shared_ptr`s. So the stream wasn't freed before `~TextDiagnosticPrinter` accessing it. But that begged the question of why these are `shared_ptr`s in the first place. This patch makes these `unique_ptr`s and fixes the destruction order that would now be an issue.
Member
|
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesThis aligns This class didn't suffer from the same lifetime issue because it used Full diff: https://github.com/llvm/llvm-project/pull/167731.diff 1 Files Affected:
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 75ed87baf636a..c99f6c6e5e2c5 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -171,9 +171,9 @@ class ClangDiagnosticManagerAdapter : public clang::DiagnosticConsumer {
: m_options(opts), m_filename(filename) {
m_options.ShowPresumedLoc = true;
m_options.ShowLevel = false;
- m_os = std::make_shared<llvm::raw_string_ostream>(m_output);
+ m_os = std::make_unique<llvm::raw_string_ostream>(m_output);
m_passthrough =
- std::make_shared<clang::TextDiagnosticPrinter>(*m_os, m_options);
+ std::make_unique<clang::TextDiagnosticPrinter>(*m_os, m_options);
}
void ResetManager(DiagnosticManager *manager = nullptr) {
@@ -315,11 +315,11 @@ class ClangDiagnosticManagerAdapter : public clang::DiagnosticConsumer {
private:
DiagnosticManager *m_manager = nullptr;
DiagnosticOptions m_options;
- std::shared_ptr<clang::TextDiagnosticPrinter> m_passthrough;
- /// Output stream of m_passthrough.
- std::shared_ptr<llvm::raw_string_ostream> m_os;
/// Output string filled by m_os.
std::string m_output;
+ /// Output stream of m_passthrough.
+ std::unique_ptr<llvm::raw_string_ostream> m_os;
+ std::unique_ptr<clang::TextDiagnosticPrinter> m_passthrough;
StringRef m_filename;
};
|
adrian-prantl
approved these changes
Nov 12, 2025
git-crd
pushed a commit
to git-crd/crd-llvm-project
that referenced
this pull request
Nov 13, 2025
…iagnosticManagerAdapter (llvm#167731) This aligns `ClangDiagnosticManagerAdapter` with how we set up the diagnostics in `ClangModulesDeclVendor`. We fixed lifetime issues around the same kind of setup here: llvm#167724 This class didn't suffer from the same lifetime issue because it used `shared_ptr`s. So the stream wasn't freed before `~TextDiagnosticPrinter` accessing it. But that begged the question of why these are `shared_ptr`s in the first place. This patch makes these `unique_ptr`s and fixes the destruction order that would now be an issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This aligns
ClangDiagnosticManagerAdapterwith how we set up the diagnostics inClangModulesDeclVendor. We fixed lifetime issues around the same kind of setup here: #167724This class didn't suffer from the same lifetime issue because it used
shared_ptrs. So the stream wasn't freed before~TextDiagnosticPrinteraccessing it. But that begged the question of why these areshared_ptrs in the first place. This patch makes theseunique_ptrs and fixes the destruction order that would now be an issue.