diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index 2b00557d2e77b..0526e87de93e0 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -1298,6 +1298,10 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager, m_compiler->setSema(nullptr); adapter->EndSourceFile(); + // Creating persistent variables can trigger diagnostic emission. + // Make sure we reset the manager so we don't get asked to handle + // diagnostics after we finished parsing. + adapter->ResetManager(); unsigned num_errors = adapter->getNumErrors(); @@ -1313,8 +1317,6 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager, type_system_helper->CommitPersistentDecls(); } - adapter->ResetManager(); - return num_errors; }