[Module trace] Eliminate use of report_fatal_error in non-assertions builds

This code path can have its invariants broken by catastrophic build
failures and needs to not crash.
This commit is contained in:
Doug Gregor
2022-12-22 09:47:47 -08:00
parent 45aea1e2e1
commit aa969c7ccb

View File

@@ -629,13 +629,12 @@ static void computeSwiftModuleTraceInfo(
// filename available. // filename available.
if (isSwiftinterface) { if (isSwiftinterface) {
// FIXME: Use PrettyStackTrace instead. // FIXME: Use PrettyStackTrace instead.
SmallVector<char, 0> errMsg; llvm::errs() << "WARNING: unexpected path for swiftinterface file:\n"
llvm::raw_svector_ostream err(errMsg); << depPath << "\n"
err << "Unexpected path for swiftinterface file:\n" << depPath << "\n"; << "The module <-> path mapping we have is:\n";
err << "The module <-> path mapping we have is:\n";
for (auto &m : pathToModuleDecl) for (auto &m : pathToModuleDecl)
err << m.second->getName() << " <-> " << m.first << '\n'; llvm::errs() << m.second->getName() << " <-> " << m.first << '\n';
llvm::report_fatal_error(errMsg); continue;
} }
// Skip cached modules in the prebuilt cache. We will add the corresponding // Skip cached modules in the prebuilt cache. We will add the corresponding
@@ -710,8 +709,11 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
llvm::DenseMap<StringRef, ModuleDecl *> pathToModuleDecl; llvm::DenseMap<StringRef, ModuleDecl *> pathToModuleDecl;
for (const auto &module : ctxt.getLoadedModules()) { for (const auto &module : ctxt.getLoadedModules()) {
ModuleDecl *loadedDecl = module.second; ModuleDecl *loadedDecl = module.second;
if (!loadedDecl) if (!loadedDecl) {
llvm::report_fatal_error("Expected loaded modules to be non-null."); llvm::errs() << "WARNING: Unable to load module '" << module.first
<< ".\n";
continue;
}
if (loadedDecl == mainModule) if (loadedDecl == mainModule)
continue; continue;
if (loadedDecl->getModuleFilename().empty()) { if (loadedDecl->getModuleFilename().empty()) {