[Serialization] Add warning when .swiftsourceinfo is malformed

Output a warning rather than ignoring a malformed .swiftsourceinfo
completely.

Resolves rdar://77350048
This commit is contained in:
Ben Barham
2021-05-01 11:31:24 +10:00
parent 246bb417dc
commit bfb9205c7c
6 changed files with 49 additions and 0 deletions

View File

@@ -686,10 +686,16 @@ LoadedFile *SerializedModuleLoaderBase::loadAST(
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
bool isFramework) {
assert(moduleInputBuffer);
// The buffers are moved into the shared core, so grab their IDs now in case
// they're needed for diagnostics later.
StringRef moduleBufferID = moduleInputBuffer->getBufferIdentifier();
StringRef moduleDocBufferID;
if (moduleDocInputBuffer)
moduleDocBufferID = moduleDocInputBuffer->getBufferIdentifier();
StringRef moduleSourceInfoID;
if (moduleSourceInfoInputBuffer)
moduleSourceInfoID = moduleSourceInfoInputBuffer->getBufferIdentifier();
if (moduleInputBuffer->getBufferSize() % 4 != 0) {
if (diagLoc)
@@ -742,6 +748,12 @@ LoadedFile *SerializedModuleLoaderBase::loadAST(
(Ctx.LangOpts.AllowModuleWithCompilerErrors &&
(loadInfo.status == serialization::Status::TargetTooNew ||
loadInfo.status == serialization::Status::TargetIncompatible))) {
if (loadedModuleFile->hasSourceInfoFile() &&
!loadedModuleFile->hasSourceInfo())
Ctx.Diags.diagnose(diagLocOrInvalid,
diag::serialization_malformed_sourceinfo,
moduleSourceInfoID);
Ctx.bumpGeneration();
LoadedModuleFiles.emplace_back(std::move(loadedModuleFile),
Ctx.getCurrentGeneration());