Skip to content

Commit d871215

Browse files
committed
Replace all mutation of m_fatal_error with calls to RaiseFatalError() (NFC)
1 parent 9c48cac commit d871215

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4806,27 +4806,15 @@ bool SwiftASTContext::SetColorizeDiagnostics(bool b) {
48064806
void SwiftASTContext::PrintDiagnostics(DiagnosticManager &diagnostic_manager,
48074807
uint32_t bufferID, uint32_t first_line,
48084808
uint32_t last_line) const {
4809+
// VALID_OR_RETURN cannot be used here here since would exit on error.
48094810
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.
48174811
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");
48274813
return;
48284814
}
48294815

4816+
// Forward diagnostics into diagnostic_manager.
4817+
// If there is a fatal error, also copy the error into m_fatal_errors.
48304818
if (m_ast_context_ap->Diags.hasFatalErrorOccurred() &&
48314819
!m_reported_fatal_error) {
48324820
DiagnosticManager fatal_diagnostics;
@@ -4836,9 +4824,9 @@ void SwiftASTContext::PrintDiagnostics(DiagnosticManager &diagnostic_manager,
48364824
->PrintDiagnostics(fatal_diagnostics, bufferID, first_line,
48374825
last_line);
48384826
if (fatal_diagnostics.Diagnostics().size())
4839-
m_fatal_errors.SetErrorString(fatal_diagnostics.GetString().c_str());
4827+
RaiseFatalError(fatal_diagnostics.GetString());
48404828
else
4841-
m_fatal_errors.SetErrorString("Unknown fatal error occurred.");
4829+
RaiseFatalError("Unknown fatal error occurred.");
48424830

48434831
m_reported_fatal_error = true;
48444832

@@ -4885,9 +4873,9 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) {
48854873
if (use_all_compiler_flags && !extra_clang_args.empty()) {
48864874
// We cannot reconfigure ClangImporter after its creation.
48874875
// 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.");
48914879
HEALTH_LOG_PRINTF(
48924880
"New Swift image added: %s. ClangImporter needs to be reinitialized.",
48934881
module_sp->GetFileSpec().GetPath().c_str());

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,16 +434,21 @@ class SwiftASTContext : public TypeSystemSwift {
434434
bool HasClangImporterErrors() const;
435435

436436
void AddDiagnostic(DiagnosticSeverity severity, llvm::StringRef message);
437-
void RaiseFatalError(std::string msg) { m_fatal_errors.SetErrorString(msg); }
437+
void RaiseFatalError(std::string msg) const {
438+
m_fatal_errors.SetErrorString(msg);
439+
}
438440
static bool HasFatalErrors(swift::ASTContext *ast_context);
439441
bool HasFatalErrors() const {
440442
return m_fatal_errors.Fail() || HasFatalErrors(m_ast_context_ap.get());
441443
}
442444

445+
/// Return all errors and warnings that haven't been cleared.
443446
Status GetAllErrors() const;
447+
/// Return only fatal errors.
444448
Status GetFatalErrors() const;
449+
/// Notify the Process about any Swift or ClangImporter errors.
445450
void DiagnoseWarnings(Process &process, Module &module) const override;
446-
void LogFatalErrors() const;
451+
447452

448453
// NEVER call this without checking HasFatalErrors() first.
449454
// This clears the fatal-error state which is terrible.
@@ -821,6 +826,9 @@ class SwiftASTContext : public TypeSystemSwift {
821826
typedef llvm::DenseMap<swift::TypeBase *, const char *>
822827
SwiftMangledNameFromTypeMap;
823828

829+
/// Called by the VALID_OR_RETURN macro to log all errors.
830+
void LogFatalErrors() const;
831+
824832
llvm::TargetOptions *getTargetOptions();
825833

826834
swift::ModuleDecl *GetScratchModule();

0 commit comments

Comments
 (0)