mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #37196 from bnbarham/warn-on-invalid-sourceinfo
[Serialization] Add warning when .swiftsourceinfo is malformed
This commit is contained in:
@@ -799,6 +799,8 @@ ERROR(serialization_error_type,Fatal,
|
||||
ERROR(serialization_allowing_error_type,none,
|
||||
"allowing deserialization of error type '%0' in module '%1'",
|
||||
(StringRef, StringRef))
|
||||
WARNING(serialization_malformed_sourceinfo,none,
|
||||
"unable to use malformed module source info '%0'", (StringRef))
|
||||
|
||||
ERROR(reserved_member_name,none,
|
||||
"type member must not be named %0, since it would conflict with the"
|
||||
|
||||
@@ -480,6 +480,13 @@ public:
|
||||
/// \c true if this module has incremental dependency information.
|
||||
bool hasIncrementalInfo() const { return Core->hasIncrementalInfo(); }
|
||||
|
||||
/// \c true if this module has a corresponding .swiftsourceinfo file.
|
||||
bool hasSourceInfoFile() const { return Core->hasSourceInfoFile(); }
|
||||
|
||||
/// \c true if this module has information from a corresponding
|
||||
/// .swiftsourceinfo file (ie. the file exists and has been read).
|
||||
bool hasSourceInfo() const { return Core->hasSourceInfo(); }
|
||||
|
||||
/// Associates this module file with the AST node representing it.
|
||||
///
|
||||
/// Checks that the file is compatible with the AST module it's being loaded
|
||||
|
||||
@@ -1496,3 +1496,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool ModuleFileSharedCore::hasSourceInfo() const {
|
||||
return !!DeclUSRsTable;
|
||||
}
|
||||
|
||||
@@ -521,6 +521,13 @@ public:
|
||||
/// Returns \c true if this module file contains a section with incremental
|
||||
/// information.
|
||||
bool hasIncrementalInfo() const { return HasIncrementalInfo; }
|
||||
|
||||
/// Returns \c true if a corresponding .swiftsourceinfo has been found.
|
||||
bool hasSourceInfoFile() const { return !!ModuleSourceInfoInputBuffer; }
|
||||
|
||||
/// Returns \c true if a corresponding .swiftsourceinfo has been found *and
|
||||
/// read*.
|
||||
bool hasSourceInfo() const;
|
||||
};
|
||||
|
||||
template <typename T, typename RawData>
|
||||
|
||||
@@ -687,10 +687,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)
|
||||
@@ -743,6 +749,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());
|
||||
|
||||
17
test/Serialization/load-invalid-sourceinfo.swift
Normal file
17
test/Serialization/load-invalid-sourceinfo.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-frontend -emit-module -o %t %S/../Inputs/empty.swift
|
||||
// RUN: %target-swift-frontend -typecheck -I %t %s
|
||||
|
||||
// RUN: touch %t/empty.swiftsourceinfo
|
||||
// RUN: %target-swift-frontend -typecheck -I %t %s -verify
|
||||
|
||||
// RUN: echo -n 'a' > %t/empty.swiftsourceinfo
|
||||
// RUN: %target-swift-frontend -typecheck -I %t %s -verify
|
||||
|
||||
// RUN: echo -n 'abcd' > %t/empty.swiftsourceinfo
|
||||
// RUN: %target-swift-frontend -typecheck -I %t %s -verify
|
||||
|
||||
// RUN: echo -n 'abcde' > %t/empty.swiftsourceinfo
|
||||
// RUN: %target-swift-frontend -typecheck -I %t %s -verify
|
||||
|
||||
import empty // expected-warning{{unable to use malformed module source info}}
|
||||
Reference in New Issue
Block a user