Skip to content

Commit 87da620

Browse files
authored
[lldb][ClangExpressionParser] Clean up ownership of members in ClangDiagnosticManagerAdapter (#167731)
This aligns `ClangDiagnosticManagerAdapter` with how we set up the diagnostics in `ClangModulesDeclVendor`. We fixed lifetime issues around the same kind of setup here: #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.
1 parent 280d0df commit 87da620

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ class ClangDiagnosticManagerAdapter : public clang::DiagnosticConsumer {
171171
: m_options(opts), m_filename(filename) {
172172
m_options.ShowPresumedLoc = true;
173173
m_options.ShowLevel = false;
174-
m_os = std::make_shared<llvm::raw_string_ostream>(m_output);
174+
m_os = std::make_unique<llvm::raw_string_ostream>(m_output);
175175
m_passthrough =
176-
std::make_shared<clang::TextDiagnosticPrinter>(*m_os, m_options);
176+
std::make_unique<clang::TextDiagnosticPrinter>(*m_os, m_options);
177177
}
178178

179179
void ResetManager(DiagnosticManager *manager = nullptr) {
@@ -315,11 +315,11 @@ class ClangDiagnosticManagerAdapter : public clang::DiagnosticConsumer {
315315
private:
316316
DiagnosticManager *m_manager = nullptr;
317317
DiagnosticOptions m_options;
318-
std::shared_ptr<clang::TextDiagnosticPrinter> m_passthrough;
319-
/// Output stream of m_passthrough.
320-
std::shared_ptr<llvm::raw_string_ostream> m_os;
321318
/// Output string filled by m_os.
322319
std::string m_output;
320+
/// Output stream of m_passthrough.
321+
std::unique_ptr<llvm::raw_string_ostream> m_os;
322+
std::unique_ptr<clang::TextDiagnosticPrinter> m_passthrough;
323323
StringRef m_filename;
324324
};
325325

0 commit comments

Comments
 (0)