Turn (most) deserialization errors from a crash into a fatal diagnostic (NFC)

Currently, ModuleFileSharedCore::fatal() calls abort(), which may be reasonable
in a swift-frontend invocation, but has dire consequences when the Swift
frontend is embedded into another process, for example, LLDB where the abort()
kills the entire debugging session.

This patch introduces a few alternatives to the ModuleFile::fatal() familiy of
functions that instead push a fatal diagnostic to the ASTContext's
DiagnosticsEngine and return an llvm::Error so the error can be roperly
communicated and the ASTContext can be wound down without killing the parent
process.

The transition is not complete, this patch does not yet handle
fatalIfUnexpected(), for example.

This patch is NFC for the Swift compiler: When DebuggerSupport in off
ModuleFile::diagnoseFatal() will still call abort(), but if it is on, the error
will be passed up, together with a pretty stack trace.

rdar://64511878
This commit is contained in:
Adrian Prantl
2022-09-30 16:10:58 -07:00
parent c266e9dce5
commit 28d7f8813c
6 changed files with 339 additions and 163 deletions

View File

@@ -711,11 +711,13 @@ ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclBaseName N,
DeclMembersTables[subTableOffset];
if (!subTable) {
BCOffsetRAII restoreOffset(DeclMemberTablesCursor);
fatalIfNotSuccess(DeclMemberTablesCursor.JumpToBit(subTableOffset));
if (diagnoseFatalIfNotSuccess(
DeclMemberTablesCursor.JumpToBit(subTableOffset)))
return results;
llvm::BitstreamEntry entry =
fatalIfUnexpected(DeclMemberTablesCursor.advance());
if (entry.Kind != llvm::BitstreamEntry::Record) {
fatal();
diagnoseAndConsumeFatal();
return results;
}
SmallVector<uint64_t, 64> scratch;