@@ -4806,27 +4806,15 @@ bool SwiftASTContext::SetColorizeDiagnostics(bool b) {
4806
4806
void SwiftASTContext::PrintDiagnostics (DiagnosticManager &diagnostic_manager,
4807
4807
uint32_t bufferID, uint32_t first_line,
4808
4808
uint32_t last_line) const {
4809
+ // VALID_OR_RETURN cannot be used here here since would exit on error.
4809
4810
LLDB_SCOPED_TIMER ();
4810
- // If this is a fatal error, copy the error into the AST context's
4811
- // fatal error field, and then put it to the stream, otherwise just
4812
- // dump the diagnostics to the stream.
4813
-
4814
- // N.B. you cannot use VALID_OR_RETURN here since that exits if
4815
- // you have fatal errors, which are what we are trying to print
4816
- // here.
4817
4811
if (!m_ast_context_ap.get ()) {
4818
- SymbolFile *sym_file = GetSymbolFile ();
4819
- if (sym_file) {
4820
- ConstString name =
4821
- sym_file->GetObjectFile ()->GetModule ()->GetObjectName ();
4822
- m_fatal_errors.SetErrorStringWithFormat (" Null context for %s." ,
4823
- name.AsCString ());
4824
- } else {
4825
- m_fatal_errors.SetErrorString (" Unknown fatal error occurred." );
4826
- }
4812
+ RaiseFatalError (" Swift compiler could not be initialized" );
4827
4813
return ;
4828
4814
}
4829
4815
4816
+ // Forward diagnostics into diagnostic_manager.
4817
+ // If there is a fatal error, also copy the error into m_fatal_errors.
4830
4818
if (m_ast_context_ap->Diags .hasFatalErrorOccurred () &&
4831
4819
!m_reported_fatal_error) {
4832
4820
DiagnosticManager fatal_diagnostics;
@@ -4836,9 +4824,9 @@ void SwiftASTContext::PrintDiagnostics(DiagnosticManager &diagnostic_manager,
4836
4824
->PrintDiagnostics (fatal_diagnostics, bufferID, first_line,
4837
4825
last_line);
4838
4826
if (fatal_diagnostics.Diagnostics ().size ())
4839
- m_fatal_errors. SetErrorString (fatal_diagnostics.GetString (). c_str ());
4827
+ RaiseFatalError (fatal_diagnostics.GetString ());
4840
4828
else
4841
- m_fatal_errors. SetErrorString (" Unknown fatal error occurred." );
4829
+ RaiseFatalError (" Unknown fatal error occurred." );
4842
4830
4843
4831
m_reported_fatal_error = true ;
4844
4832
@@ -4885,9 +4873,9 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) {
4885
4873
if (use_all_compiler_flags && !extra_clang_args.empty ()) {
4886
4874
// We cannot reconfigure ClangImporter after its creation.
4887
4875
// Instead poison the SwiftASTContext so it gets recreated.
4888
- m_fatal_errors. SetErrorStringWithFormat (
4889
- " New Swift image added: %s. ClangImporter needs to be reinitialized. " ,
4890
- module_sp-> GetFileSpec (). GetPath (). c_str () );
4876
+ RaiseFatalError (
4877
+ " New Swift image added: " + module_sp-> GetFileSpec (). GetPath () +
4878
+ " ClangImporter needs to be reinitialized. " );
4891
4879
HEALTH_LOG_PRINTF (
4892
4880
" New Swift image added: %s. ClangImporter needs to be reinitialized." ,
4893
4881
module_sp->GetFileSpec ().GetPath ().c_str ());
0 commit comments