From cca27289e3ee41c31aee2f0b06c18f34c7f2a8c1 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Wed, 19 Jun 2019 19:09:14 -0700 Subject: [PATCH 001/115] [ClangImporter] Handle newly-introduced Clang sugar types (#25522) And `delete` SwiftTypeConverter::VisitType, so that we find out about these at compile time in the future. rdar://50999584 --- lib/ClangImporter/ImportType.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index d8c2711060093..75c746aafe277 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -189,13 +189,15 @@ namespace { return IR; } + ImportResult VisitType(const Type*) = delete; + #define DEPENDENT_TYPE(Class, Base) \ ImportResult Visit##Class##Type(const clang::Class##Type *) { \ llvm_unreachable("Dependent types cannot be converted"); \ } #define TYPE(Class, Base) #include "clang/AST/TypeNodes.def" - + // Given a loaded type like CInt, look through the type alias sugar that the // stdlib uses to show the underlying type. We want to import the signature // of the exit(3) libc function as "func exit(Int32)", not as @@ -334,6 +336,11 @@ namespace { llvm_unreachable("Invalid BuiltinType."); } + ImportResult VisitPipeType(const clang::PipeType *) { + // OpenCL types are not supported in Swift. + return Type(); + } + ImportResult VisitComplexType(const clang::ComplexType *type) { // FIXME: Implement once Complex is in the library. return Type(); @@ -795,12 +802,11 @@ namespace { SUGAR_TYPE(SubstTemplateTypeParm) SUGAR_TYPE(TemplateSpecialization) SUGAR_TYPE(Auto) + SUGAR_TYPE(DeducedTemplateSpecialization) SUGAR_TYPE(Adjusted) SUGAR_TYPE(PackExpansion) - - ImportResult VisitAttributedType(const clang::AttributedType *type) { - return Visit(type->desugar()); - } + SUGAR_TYPE(Attributed) + SUGAR_TYPE(MacroQualified) ImportResult VisitDecayedType(const clang::DecayedType *type) { clang::ASTContext &clangCtx = Impl.getClangASTContext(); From 50de105bf1f9050047ebb4cf07c01db41ab6ddcb Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Mon, 1 Jul 2019 10:08:41 -0700 Subject: [PATCH 002/115] Fix Swift following bitstream reader API update (#25845) * Fix Swift following bitstream reader API update Upstream change in rL364464 broke downstream Swift. --- include/swift/Serialization/BCReadingExtras.h | 3 +- include/swift/Serialization/ModuleFile.h | 9 + lib/ClangImporter/SwiftLookupTable.cpp | 35 +- lib/Serialization/Deserialization.cpp | 214 +++++++----- lib/Serialization/DeserializeSIL.cpp | 207 ++++++++--- lib/Serialization/ModuleFile.cpp | 324 +++++++++++++++--- tools/driver/modulewrap_main.cpp | 15 +- 7 files changed, 622 insertions(+), 185 deletions(-) diff --git a/include/swift/Serialization/BCReadingExtras.h b/include/swift/Serialization/BCReadingExtras.h index 1ef3e8e33ad8e..b09ca4b52b932 100644 --- a/include/swift/Serialization/BCReadingExtras.h +++ b/include/swift/Serialization/BCReadingExtras.h @@ -38,7 +38,8 @@ class BCOffsetRAII { ~BCOffsetRAII() { if (Cursor) - Cursor->JumpToBit(Offset); + cantFail(Cursor->JumpToBit(Offset), + "BCOffsetRAII must be able to go back"); } }; diff --git a/include/swift/Serialization/ModuleFile.h b/include/swift/Serialization/ModuleFile.h index 917d790dbb5c7..ec1db7ff8ed45 100644 --- a/include/swift/Serialization/ModuleFile.h +++ b/include/swift/Serialization/ModuleFile.h @@ -502,6 +502,15 @@ class ModuleFile /// Emits one last diagnostic, logs the error, and then aborts for the stack /// trace. LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error error); + void fatalIfNotSuccess(llvm::Error error) { + if (error) + fatal(std::move(error)); + } + template T fatalIfUnexpected(llvm::Expected expected) { + if (expected) + return std::move(expected.get()); + fatal(expected.takeError()); + } ASTContext &getContext() const { assert(FileContext && "no associated context yet"); diff --git a/lib/ClangImporter/SwiftLookupTable.cpp b/lib/ClangImporter/SwiftLookupTable.cpp index 1e7dea01dd5d4..fdd9be0205f7c 100644 --- a/lib/ClangImporter/SwiftLookupTable.cpp +++ b/lib/ClangImporter/SwiftLookupTable.cpp @@ -1460,7 +1460,13 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension, // Look for the base name -> entities table record. SmallVector scratch; auto cursor = stream; - auto next = cursor.advance(); + llvm::Expected maybeNext = cursor.advance(); + if (!maybeNext) { + // FIXME this drops the error on the floor. + consumeError(maybeNext.takeError()); + return nullptr; + } + llvm::BitstreamEntry next = maybeNext.get(); std::unique_ptr serializedTable; std::unique_ptr globalsAsMembersTable; ArrayRef categories; @@ -1473,14 +1479,27 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension, // API notes format. if (cursor.SkipBlock()) return nullptr; - - next = cursor.advance(); + + maybeNext = cursor.advance(); + if (!maybeNext) { + // FIXME this drops the error on the floor. + consumeError(maybeNext.takeError()); + return nullptr; + } + next = maybeNext.get(); continue; } scratch.clear(); StringRef blobData; - unsigned kind = cursor.readRecord(next.ID, scratch, &blobData); + llvm::Expected maybeKind = + cursor.readRecord(next.ID, scratch, &blobData); + if (!maybeKind) { + // FIXME this drops the error on the floor. + consumeError(maybeNext.takeError()); + return nullptr; + } + unsigned kind = maybeKind.get(); switch (kind) { case BASE_NAME_TO_ENTITIES_RECORD_ID: { // Already saw base name -> entities table. @@ -1532,7 +1551,13 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension, break; } - next = cursor.advance(); + maybeNext = cursor.advance(); + if (!maybeNext) { + // FIXME this drops the error on the floor. + consumeError(maybeNext.takeError()); + return nullptr; + } + next = maybeNext.get(); } if (!serializedTable) return nullptr; diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 63746606e244c..5c112f0d9b280 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -137,10 +137,10 @@ void ExtensionError::anchor() {} /// Skips a single record in the bitstream. /// -/// Returns true if the next entry is a record of type \p recordKind. /// Destroys the stream position if the next entry is not a record. static void skipRecord(llvm::BitstreamCursor &cursor, unsigned recordKind) { - auto next = cursor.advance(AF_DontPopBlockAtEnd); + auto next = llvm::cantFail( + cursor.advance(AF_DontPopBlockAtEnd)); assert(next.Kind == llvm::BitstreamEntry::Record); #if NDEBUG @@ -148,7 +148,9 @@ static void skipRecord(llvm::BitstreamCursor &cursor, unsigned recordKind) { #else SmallVector scratch; StringRef blobData; - unsigned kind = cursor.readRecord(next.ID, scratch, &blobData); + auto kind = + llvm::cantFail(cursor.readRecord(next.ID, scratch, &blobData)); + (void)kind; assert(kind == recordKind); #endif } @@ -250,8 +252,10 @@ ParameterList *ModuleFile::readParameterList() { using namespace decls_block; SmallVector scratch; - auto entry = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); - unsigned recordID = DeclTypeCursor.readRecord(entry.ID, scratch); + llvm::BitstreamEntry entry = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); + unsigned recordID = + fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch)); assert(recordID == PARAMETERLIST); (void) recordID; @@ -283,7 +287,8 @@ Expected ModuleFile::readPattern(DeclContext *owningDC) { SmallVector scratch; BCOffsetRAII restoreOffset(DeclTypeCursor); - auto next = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry next = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (next.Kind != llvm::BitstreamEntry::Record) { error(); return nullptr; @@ -297,7 +302,8 @@ Expected ModuleFile::readPattern(DeclContext *owningDC) { pattern->setType(type); }; - unsigned kind = DeclTypeCursor.readRecord(next.ID, scratch); + unsigned kind = + fatalIfUnexpected(DeclTypeCursor.readRecord(next.ID, scratch)); switch (kind) { case decls_block::PAREN_PATTERN: { bool isImplicit; @@ -328,10 +334,10 @@ Expected ModuleFile::readPattern(DeclContext *owningDC) { SmallVector elements; for ( ; count > 0; --count) { scratch.clear(); - next = DeclTypeCursor.advance(); + next = fatalIfUnexpected(DeclTypeCursor.advance()); assert(next.Kind == llvm::BitstreamEntry::Record); - kind = DeclTypeCursor.readRecord(next.ID, scratch); + kind = fatalIfUnexpected(DeclTypeCursor.readRecord(next.ID, scratch)); assert(kind == decls_block::TUPLE_PATTERN_ELT); // FIXME: Add something for this record or remove it. @@ -423,10 +429,11 @@ SILLayout *ModuleFile::readSILLayout(llvm::BitstreamCursor &Cursor) { SmallVector scratch; - auto next = Cursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry next = + fatalIfUnexpected(Cursor.advance(AF_DontPopBlockAtEnd)); assert(next.Kind == llvm::BitstreamEntry::Record); - unsigned kind = Cursor.readRecord(next.ID, scratch); + unsigned kind = fatalIfUnexpected(Cursor.readRecord(next.ID, scratch)); switch (kind) { case decls_block::SIL_LAYOUT: { GenericSignatureID rawGenericSig; @@ -462,13 +469,14 @@ ProtocolConformanceRef ModuleFile::readConformance( SmallVector scratch; - auto next = Cursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry next = + fatalIfUnexpected(Cursor.advance(AF_DontPopBlockAtEnd)); assert(next.Kind == llvm::BitstreamEntry::Record); if (getContext().Stats) getContext().Stats->getFrontendCounters().NumConformancesDeserialized++; - unsigned kind = Cursor.readRecord(next.ID, scratch); + unsigned kind = fatalIfUnexpected(Cursor.readRecord(next.ID, scratch)); switch (kind) { case INVALID_PROTOCOL_CONFORMANCE: { return ProtocolConformanceRef::forInvalid(); @@ -601,8 +609,8 @@ NormalProtocolConformance *ModuleFile::readNormalConformance( // Find the conformance record. BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(conformanceEntry); - auto entry = DeclTypeCursor.advance(); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(conformanceEntry)); + llvm::BitstreamEntry entry = fatalIfUnexpected(DeclTypeCursor.advance()); if (entry.Kind != llvm::BitstreamEntry::Record) { error(); return nullptr; @@ -614,7 +622,8 @@ NormalProtocolConformance *ModuleFile::readNormalConformance( ArrayRef rawIDs; SmallVector scratch; - unsigned kind = DeclTypeCursor.readRecord(entry.ID, scratch); + unsigned kind = + fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch)); if (kind != NORMAL_PROTOCOL_CONFORMANCE) { error(); return nullptr; @@ -665,11 +674,13 @@ GenericParamList *ModuleFile::maybeReadGenericParams(DeclContext *DC) { SmallVector scratch; StringRef blobData; - auto next = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry next = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (next.Kind != llvm::BitstreamEntry::Record) return nullptr; - unsigned kind = DeclTypeCursor.readRecord(next.ID, scratch, &blobData); + unsigned kind = + fatalIfUnexpected(DeclTypeCursor.readRecord(next.ID, scratch, &blobData)); if (kind != GENERIC_PARAM_LIST) return nullptr; lastRecordOffset.reset(); @@ -706,12 +717,14 @@ void ModuleFile::readGenericRequirements( lastRecordOffset.reset(); bool shouldContinue = true; - auto entry = Cursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry entry = + fatalIfUnexpected(Cursor.advance(AF_DontPopBlockAtEnd)); if (entry.Kind != llvm::BitstreamEntry::Record) break; scratch.clear(); - unsigned recordID = Cursor.readRecord(entry.ID, scratch, &blobData); + unsigned recordID = fatalIfUnexpected( + DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); switch (recordID) { case GENERIC_REQUIREMENT: { uint8_t rawKind; @@ -818,29 +831,36 @@ void ModuleFile::readGenericRequirements( } /// Advances past any records that might be part of a requirement signature. -static void skipGenericRequirements(llvm::BitstreamCursor &Cursor) { +static llvm::Error skipGenericRequirements(llvm::BitstreamCursor &Cursor) { using namespace decls_block; BCOffsetRAII lastRecordOffset(Cursor); while (true) { - auto entry = Cursor.advance(AF_DontPopBlockAtEnd); + Expected maybeEntry = + Cursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + return maybeEntry.takeError(); + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind != llvm::BitstreamEntry::Record) break; - unsigned recordID = Cursor.skipRecord(entry.ID); - switch (recordID) { + Expected maybeRecordID = Cursor.skipRecord(entry.ID); + if (!maybeRecordID) + return maybeRecordID.takeError(); + switch (maybeRecordID.get()) { case GENERIC_REQUIREMENT: case LAYOUT_REQUIREMENT: break; default: // This record is not a generic requirement. - return; + return llvm::Error::success(); } lastRecordOffset.reset(); } + return llvm::Error::success(); } void ModuleFile::configureGenericEnvironment( @@ -882,7 +902,7 @@ GenericSignature *ModuleFile::getGenericSignature( // Read the generic signature. BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(sigOrOffset); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(sigOrOffset)); DeserializingEntityRAII deserializingEntity(*this); // Read the parameter types. @@ -890,13 +910,15 @@ GenericSignature *ModuleFile::getGenericSignature( StringRef blobData; SmallVector scratch; - auto entry = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry entry = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (entry.Kind != llvm::BitstreamEntry::Record) { error(); return nullptr; } - unsigned recordID = DeclTypeCursor.readRecord(entry.ID, scratch, &blobData); + unsigned recordID = fatalIfUnexpected( + DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); if (recordID != GENERIC_SIGNATURE) { error(); return nullptr; @@ -958,7 +980,7 @@ ModuleFile::getGenericSignatureOrEnvironment( // Read the generic environment. BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(bitOffset); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(bitOffset)); DeserializingEntityRAII deserializingEntity(*this); SmallVector paramTypes; @@ -973,11 +995,13 @@ ModuleFile::getGenericSignatureOrEnvironment( // own internal tracking.) BCOffsetRAII lastRecordOffset(DeclTypeCursor); - auto entry = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry entry = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (entry.Kind != llvm::BitstreamEntry::Record) return result; - unsigned recordID = DeclTypeCursor.readRecord(entry.ID, scratch, &blobData); + unsigned recordID = fatalIfUnexpected( + DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); if (recordID != SIL_GENERIC_ENVIRONMENT) { error(); return result; @@ -1066,11 +1090,12 @@ SubstitutionMap ModuleFile::getSubstitutionMap( // Read the substitution map. BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(substitutionsOrOffset); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(substitutionsOrOffset)); DeserializingEntityRAII deserializingEntity(*this); // Read the substitution map. - auto entry = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry entry = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (entry.Kind != llvm::BitstreamEntry::Record) { error(); return SubstitutionMap(); @@ -1078,7 +1103,8 @@ SubstitutionMap ModuleFile::getSubstitutionMap( StringRef blobData; SmallVector scratch; - unsigned recordID = DeclTypeCursor.readRecord(entry.ID, scratch, &blobData); + unsigned recordID = fatalIfUnexpected( + DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); if (recordID != SUBSTITUTION_MAP) { error(); return SubstitutionMap(); @@ -1123,13 +1149,15 @@ SubstitutionMap ModuleFile::getSubstitutionMap( bool ModuleFile::readDefaultWitnessTable(ProtocolDecl *proto) { using namespace decls_block; - auto entry = DeclTypeCursor.advance(); + llvm::BitstreamEntry entry = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (entry.Kind != llvm::BitstreamEntry::Record) return true; SmallVector witnessIDBuffer; - unsigned kind = DeclTypeCursor.readRecord(entry.ID, witnessIDBuffer); + unsigned kind = + fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, witnessIDBuffer)); assert(kind == DEFAULT_WITNESS_TABLE); (void)kind; @@ -1278,7 +1306,8 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) { assert(baseModule && "missing dependency"); PrettyXRefTrace pathTrace(*baseModule); - auto entry = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry entry = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (entry.Kind != llvm::BitstreamEntry::Record) { error(); return nullptr; @@ -1293,8 +1322,8 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) { // In particular, operator path pieces represent actual operators here, but // filters on operator functions when they appear later on. scratch.clear(); - unsigned recordID = DeclTypeCursor.readRecord(entry.ID, scratch, - &blobData); + unsigned recordID = fatalIfUnexpected( + DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); switch (recordID) { case XREF_TYPE_PATH_PIECE: case XREF_VALUE_PATH_PIECE: { @@ -1322,7 +1351,7 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) { auto maybeType = getTypeChecked(TID); if (!maybeType) { // FIXME: Don't throw away the inner error's information. - llvm::consumeError(maybeType.takeError()); + consumeError(maybeType.takeError()); return llvm::make_error("couldn't decode type", pathTrace, name); } @@ -1398,13 +1427,14 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) { auto getXRefDeclNameForError = [&]() -> DeclName { DeclName result = pathTrace.getLastName(); while (--pathLen) { - auto entry = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry entry = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (entry.Kind != llvm::BitstreamEntry::Record) return Identifier(); scratch.clear(); - unsigned recordID = DeclTypeCursor.readRecord(entry.ID, scratch, - &blobData); + unsigned recordID = fatalIfUnexpected( + DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); switch (recordID) { case XREF_TYPE_PATH_PIECE: { IdentifierID IID; @@ -1467,15 +1497,16 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) { // For remaining path pieces, filter or drill down into the results we have. while (--pathLen) { - auto entry = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry entry = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (entry.Kind != llvm::BitstreamEntry::Record) { error(); return nullptr; } scratch.clear(); - unsigned recordID = DeclTypeCursor.readRecord(entry.ID, scratch, - &blobData); + unsigned recordID = fatalIfUnexpected( + DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); switch (recordID) { case XREF_TYPE_PATH_PIECE: { if (values.size() == 1 && isa(values.front())) { @@ -1581,7 +1612,7 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) { auto maybeType = getTypeChecked(TID); if (!maybeType) { // FIXME: Don't throw away the inner error's information. - llvm::consumeError(maybeType.takeError()); + consumeError(maybeType.takeError()); return llvm::make_error("couldn't decode type", pathTrace, memberName); } @@ -1875,8 +1906,8 @@ DeclContext *ModuleFile::getLocalDeclContext(DeclContextID DCID) { return declContextOrOffset; BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(declContextOrOffset); - auto entry = DeclTypeCursor.advance(); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(declContextOrOffset)); + llvm::BitstreamEntry entry = fatalIfUnexpected(DeclTypeCursor.advance()); if (entry.Kind != llvm::BitstreamEntry::Record) { error(); @@ -1887,8 +1918,8 @@ DeclContext *ModuleFile::getLocalDeclContext(DeclContextID DCID) { SmallVector scratch; StringRef blobData; - unsigned recordID = DeclTypeCursor.readRecord(entry.ID, scratch, - &blobData); + unsigned recordID = fatalIfUnexpected( + DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); switch(recordID) { case decls_block::ABSTRACT_CLOSURE_EXPR_CONTEXT: { TypeID closureTypeID; @@ -1967,8 +1998,8 @@ DeclContext *ModuleFile::getDeclContext(DeclContextID DCID) { return declContextOrOffset; BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(declContextOrOffset); - auto entry = DeclTypeCursor.advance(); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(declContextOrOffset)); + llvm::BitstreamEntry entry = fatalIfUnexpected(DeclTypeCursor.advance()); if (entry.Kind != llvm::BitstreamEntry::Record) { error(); @@ -1978,7 +2009,8 @@ DeclContext *ModuleFile::getDeclContext(DeclContextID DCID) { SmallVector scratch; StringRef blobData; - unsigned recordID = DeclTypeCursor.readRecord(entry.ID, scratch, &blobData); + unsigned recordID = fatalIfUnexpected( + DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); if (recordID != decls_block::DECL_CONTEXT) llvm_unreachable("Expected a DECL_CONTEXT record"); @@ -3348,7 +3380,8 @@ class swift::DeclDeserializer { proto->setLazyRequirementSignature(&MF, MF.DeclTypeCursor.GetCurrentBitNo()); - skipGenericRequirements(MF.DeclTypeCursor); + if (llvm::Error Err = skipGenericRequirements(MF.DeclTypeCursor)) + MF.fatal(std::move(Err)); proto->setMemberLoader(&MF, MF.DeclTypeCursor.GetCurrentBitNo()); @@ -3964,7 +3997,7 @@ ModuleFile::getDeclChecked(DeclID DID) { if (!declOrOffset.isComplete()) { ++NumDeclsLoaded; BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(declOrOffset); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(declOrOffset)); ModuleFile::DeserializingEntityRAII deserializingEntity(*this); Expected deserialized = @@ -3993,15 +4026,16 @@ llvm::Error DeclDeserializer::deserializeDeclAttributes() { StringRef blobData; while (true) { BCOffsetRAII restoreOffset(MF.DeclTypeCursor); - auto entry = MF.DeclTypeCursor.advance(); + llvm::BitstreamEntry entry = + MF.fatalIfUnexpected(MF.DeclTypeCursor.advance()); if (entry.Kind != llvm::BitstreamEntry::Record) { // We don't know how to serialize decls represented by sub-blocks. MF.error(); return llvm::Error::success(); } - unsigned recordID = MF.DeclTypeCursor.readRecord(entry.ID, scratch, - &blobData); + unsigned recordID = MF.fatalIfUnexpected( + MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); if (isDeclAttrRecord(recordID)) { DeclAttribute *Attr = nullptr; @@ -4303,7 +4337,8 @@ DeclDeserializer::getDeclCheckedImpl() { if (declOrOffset.isComplete()) return declOrOffset; - auto entry = MF.DeclTypeCursor.advance(); + llvm::BitstreamEntry entry = + MF.fatalIfUnexpected(MF.DeclTypeCursor.advance()); if (entry.Kind != llvm::BitstreamEntry::Record) { // We don't know how to serialize decls represented by sub-blocks. MF.error(); @@ -4312,8 +4347,8 @@ DeclDeserializer::getDeclCheckedImpl() { SmallVector scratch; StringRef blobData; - unsigned recordID = MF.DeclTypeCursor.readRecord(entry.ID, scratch, - &blobData); + unsigned recordID = MF.fatalIfUnexpected( + MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); PrettyDeclDeserialization stackTraceEntry( &MF, declOrOffset, static_cast(recordID)); @@ -4690,13 +4725,14 @@ class swift::TypeDeserializer { // The tuple record itself is empty. Read all trailing elements. SmallVector elements; while (true) { - auto entry = MF.DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry entry = + MF.fatalIfUnexpected(MF.DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (entry.Kind != llvm::BitstreamEntry::Record) break; scratch.clear(); - unsigned recordID = MF.DeclTypeCursor.readRecord(entry.ID, scratch, - &blobData); + unsigned recordID = MF.fatalIfUnexpected( + MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); if (recordID != decls_block::TUPLE_TYPE_ELT) break; @@ -4751,13 +4787,14 @@ class swift::TypeDeserializer { SmallVector params; while (true) { - auto entry = MF.DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry entry = + MF.fatalIfUnexpected(MF.DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (entry.Kind != llvm::BitstreamEntry::Record) break; scratch.clear(); - unsigned recordID = MF.DeclTypeCursor.readRecord(entry.ID, scratch, - &blobData); + unsigned recordID = MF.fatalIfUnexpected( + MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); if (recordID != decls_block::FUNCTION_PARAM) break; @@ -5064,7 +5101,7 @@ class swift::TypeDeserializer { } BCOffsetRAII saveOffset(MF.DeclTypeCursor); - MF.DeclTypeCursor.JumpToBit(layoutOrOffset); + MF.fatalIfNotSuccess(MF.DeclTypeCursor.JumpToBit(layoutOrOffset)); auto layout = MF.readSILLayout(MF.DeclTypeCursor); if (!layout) { MF.error(); @@ -5310,7 +5347,7 @@ Expected ModuleFile::getTypeChecked(TypeID TID) { return typeOrOffset; BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(typeOrOffset); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(typeOrOffset)); auto result = TypeDeserializer(*this).getTypeCheckedImpl(); if (!result) @@ -5335,7 +5372,8 @@ Expected TypeDeserializer::getTypeCheckedImpl() { if (auto s = ctx.Stats) s->getFrontendCounters().NumTypesDeserialized++; - auto entry = MF.DeclTypeCursor.advance(); + llvm::BitstreamEntry entry = + MF.fatalIfUnexpected(MF.DeclTypeCursor.advance()); if (entry.Kind != llvm::BitstreamEntry::Record) { // We don't know how to serialize types represented by sub-blocks. @@ -5345,8 +5383,8 @@ Expected TypeDeserializer::getTypeCheckedImpl() { SmallVector scratch; StringRef blobData; - unsigned recordID = MF.DeclTypeCursor.readRecord(entry.ID, scratch, - &blobData); + unsigned recordID = MF.fatalIfUnexpected( + MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); switch (recordID) { #define CASE(RECORD_NAME) \ @@ -5475,8 +5513,8 @@ void ModuleFile::loadAllMembers(Decl *container, uint64_t contextData) { IDC = cast(container); BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(contextData); - auto entry = DeclTypeCursor.advance(); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(contextData)); + llvm::BitstreamEntry entry = fatalIfUnexpected(DeclTypeCursor.advance()); if (entry.Kind != llvm::BitstreamEntry::Record) { error(); return; @@ -5484,7 +5522,8 @@ void ModuleFile::loadAllMembers(Decl *container, uint64_t contextData) { SmallVector memberIDBuffer; - unsigned kind = DeclTypeCursor.readRecord(entry.ID, memberIDBuffer); + unsigned kind = + fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, memberIDBuffer)); assert(kind == decls_block::MEMBERS); (void)kind; @@ -5534,7 +5573,7 @@ ModuleFile::loadAllConformances(const Decl *D, uint64_t contextData, = decodeLazyConformanceContextData(contextData); BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(bitPosition); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(bitPosition)); while (numConformances--) { auto conf = readConformance(DeclTypeCursor); @@ -5566,8 +5605,8 @@ void ModuleFile::finishNormalConformance(NormalProtocolConformance *conformance, // Find the conformance record. BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(contextData); - auto entry = DeclTypeCursor.advance(); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(contextData)); + llvm::BitstreamEntry entry = fatalIfUnexpected(DeclTypeCursor.advance()); assert(entry.Kind == llvm::BitstreamEntry::Record && "registered lazy loader incorrectly"); @@ -5577,7 +5616,8 @@ void ModuleFile::finishNormalConformance(NormalProtocolConformance *conformance, ArrayRef rawIDs; SmallVector scratch; - unsigned kind = DeclTypeCursor.readRecord(entry.ID, scratch); + unsigned kind = + fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch)); (void) kind; assert(kind == NORMAL_PROTOCOL_CONFORMANCE && "registered lazy loader incorrectly"); @@ -5771,7 +5811,7 @@ void ModuleFile::loadRequirementSignature(const ProtocolDecl *decl, uint64_t contextData, SmallVectorImpl &reqs) { BCOffsetRAII restoreOffset(DeclTypeCursor); - DeclTypeCursor.JumpToBit(contextData); + fatalIfNotSuccess(DeclTypeCursor.JumpToBit(contextData)); readGenericRequirements(reqs, DeclTypeCursor); } @@ -5800,11 +5840,13 @@ Optional ModuleFile::maybeReadInlinableBodyText() { BCOffsetRAII restoreOffset(DeclTypeCursor); StringRef blobData; - auto next = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry next = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (next.Kind != llvm::BitstreamEntry::Record) return None; - unsigned recKind = DeclTypeCursor.readRecord(next.ID, scratch, &blobData); + unsigned recKind = + fatalIfUnexpected(DeclTypeCursor.readRecord(next.ID, scratch, &blobData)); if (recKind != INLINABLE_BODY_TEXT) return None; @@ -5819,11 +5861,13 @@ Optional ModuleFile::maybeReadForeignErrorConvention() { BCOffsetRAII restoreOffset(DeclTypeCursor); - auto next = DeclTypeCursor.advance(AF_DontPopBlockAtEnd); + llvm::BitstreamEntry next = + fatalIfUnexpected(DeclTypeCursor.advance(AF_DontPopBlockAtEnd)); if (next.Kind != llvm::BitstreamEntry::Record) return None; - unsigned recKind = DeclTypeCursor.readRecord(next.ID, scratch); + unsigned recKind = + fatalIfUnexpected(DeclTypeCursor.readRecord(next.ID, scratch)); switch (recKind) { case FOREIGN_ERROR_CONVENTION: restoreOffset.reset(); diff --git a/lib/Serialization/DeserializeSIL.cpp b/lib/Serialization/DeserializeSIL.cpp index 8ec5b6bc9460f..c09788ca63d86 100644 --- a/lib/Serialization/DeserializeSIL.cpp +++ b/lib/Serialization/DeserializeSIL.cpp @@ -141,7 +141,7 @@ SILDeserializer::SILDeserializer( return; // Load any abbrev records at the start of the block. - SILCursor.advance(); + MF->fatalIfUnexpected(SILCursor.advance()); llvm::BitstreamCursor cursor = SILIndexCursor; // We expect SIL_FUNC_NAMES first, then SIL_VTABLE_NAMES, then @@ -150,14 +150,15 @@ SILDeserializer::SILDeserializer( // omitted if no entries exist in the module file. unsigned kind = 0; while (kind != sil_index_block::SIL_PROPERTY_OFFSETS) { - auto next = cursor.advance(); + llvm::BitstreamEntry next = MF->fatalIfUnexpected(cursor.advance()); if (next.Kind == llvm::BitstreamEntry::EndBlock) return; SmallVector scratch; StringRef blobData; unsigned prevKind = kind; - kind = cursor.readRecord(next.ID, scratch, &blobData); + kind = + MF->fatalIfUnexpected(cursor.readRecord(next.ID, scratch, &blobData)); assert((next.Kind == llvm::BitstreamEntry::Record && kind > prevKind && (kind == sil_index_block::SIL_FUNC_NAMES || @@ -187,9 +188,10 @@ SILDeserializer::SILDeserializer( } // Read SIL_FUNC|VTABLE|GLOBALVAR_OFFSETS record. - next = cursor.advance(); + next = MF->fatalIfUnexpected(cursor.advance()); scratch.clear(); - unsigned offKind = cursor.readRecord(next.ID, scratch, &blobData); + unsigned offKind = + MF->fatalIfUnexpected(cursor.readRecord(next.ID, scratch, &blobData)); (void)offKind; if (kind == sil_index_block::SIL_FUNC_NAMES) { assert((next.Kind == llvm::BitstreamEntry::Record && @@ -449,9 +451,14 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn, return cacheEntry.get(); BCOffsetRAII restoreOffset(SILCursor); - SILCursor.JumpToBit(cacheEntry.getOffset()); - - auto entry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (llvm::Error Err = SILCursor.JumpToBit(cacheEntry.getOffset())) + return std::move(Err); + + llvm::Expected maybeEntry = + SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + return maybeEntry.takeError(); + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::Error) { LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in readSILFunction.\n"); MF->error(); @@ -460,7 +467,11 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn, SmallVector scratch; StringRef blobData; - unsigned kind = SILCursor.readRecord(entry.ID, scratch, &blobData); + llvm::Expected maybeKind = + SILCursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + unsigned kind = maybeKind.get(); assert(kind == SIL_FUNCTION && "expect a sil function"); (void)kind; @@ -491,7 +502,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn, return llvm::make_error( name, takeErrorInfo(astType.takeError())); } - llvm::consumeError(astType.takeError()); + consumeError(astType.takeError()); return existingFn; } auto ty = getSILType(astType.get(), SILValueCategory::Object); @@ -616,11 +627,18 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn, // Read and instantiate the specialize attributes. while (numSpecAttrs--) { - auto next = SILCursor.advance(AF_DontPopBlockAtEnd); + llvm::Expected maybeNext = + SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeNext) + return maybeNext.takeError(); + llvm::BitstreamEntry next = maybeNext.get(); assert(next.Kind == llvm::BitstreamEntry::Record); scratch.clear(); - kind = SILCursor.readRecord(next.ID, scratch); + llvm::Expected maybeKind = SILCursor.readRecord(next.ID, scratch); + if (!maybeKind) + return maybeKind.takeError(); + unsigned kind = maybeKind.get(); assert(kind == SIL_SPECIALIZE_ATTR && "Missing specialization attribute"); unsigned exported; @@ -644,7 +662,10 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn, // If the next entry is the end of the block, then this function has // no contents. - entry = SILCursor.advance(AF_DontPopBlockAtEnd); + maybeEntry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + return maybeEntry.takeError(); + entry = maybeEntry.get(); bool isEmptyFunction = (entry.Kind == llvm::BitstreamEntry::EndBlock); assert((!isEmptyFunction || !genericEnv) && "generic environment without body?!"); @@ -675,7 +696,10 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn, fn->setGenericEnvironment(genericEnv); scratch.clear(); - kind = SILCursor.readRecord(entry.ID, scratch); + maybeKind = SILCursor.readRecord(entry.ID, scratch); + if (!maybeKind) + return maybeKind.takeError(); + kind = maybeKind.get(); SILBasicBlock *CurrentBB = nullptr; @@ -735,12 +759,19 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn, // Fetch the next record. scratch.clear(); - entry = SILCursor.advance(AF_DontPopBlockAtEnd); + llvm::Expected maybeEntry = + SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + return maybeEntry.takeError(); + llvm::BitstreamEntry entry = maybeEntry.get(); // EndBlock means the end of this SILFunction. if (entry.Kind == llvm::BitstreamEntry::EndBlock) break; - kind = SILCursor.readRecord(entry.ID, scratch); + maybeKind = SILCursor.readRecord(entry.ID, scratch); + if (!maybeKind) + return maybeKind.takeError(); + kind = maybeKind.get(); } // If fn is empty, we failed to deserialize its body. Return nullptr to signal @@ -2472,7 +2503,7 @@ SILFunction *SILDeserializer::lookupSILFunction(SILFunction *InFunc) { /*declarationOnly*/ false); if (!maybeFunc) { // Ignore the error; treat it as if we didn't have a definition. - llvm::consumeError(maybeFunc.takeError()); + consumeError(maybeFunc.takeError()); return nullptr; } @@ -2505,9 +2536,14 @@ bool SILDeserializer::hasSILFunction(StringRef Name, return !Linkage || cacheEntry.get()->getLinkage() == *Linkage; BCOffsetRAII restoreOffset(SILCursor); - SILCursor.JumpToBit(cacheEntry.getOffset()); - - auto entry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (llvm::Error Err = SILCursor.JumpToBit(cacheEntry.getOffset())) + MF->fatal(std::move(Err)); + + llvm::Expected maybeEntry = + SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::Error) { LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in hasSILFunction.\n"); MF->error(); @@ -2516,7 +2552,11 @@ bool SILDeserializer::hasSILFunction(StringRef Name, SmallVector scratch; StringRef blobData; - unsigned kind = SILCursor.readRecord(entry.ID, scratch, &blobData); + llvm::Expected maybeKind = + SILCursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + unsigned kind = maybeKind.get(); assert(kind == SIL_FUNCTION && "expect a sil function"); (void)kind; @@ -2567,7 +2607,7 @@ SILFunction *SILDeserializer::lookupSILFunction(StringRef name, if (!maybeFunc) { // Ignore the error; treat it as if we didn't have a definition. - llvm::consumeError(maybeFunc.takeError()); + consumeError(maybeFunc.takeError()); return nullptr; } @@ -2602,8 +2642,13 @@ SILGlobalVariable *SILDeserializer::readGlobalVar(StringRef Name) { return globalVarOrOffset; BCOffsetRAII restoreOffset(SILCursor); - SILCursor.JumpToBit(globalVarOrOffset); - auto entry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (llvm::Error Err = SILCursor.JumpToBit(globalVarOrOffset)) + MF->fatal(std::move(Err)); + llvm::Expected maybeEntry = + SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::Error) { LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in readGlobalVar.\n"); return nullptr; @@ -2611,7 +2656,11 @@ SILGlobalVariable *SILDeserializer::readGlobalVar(StringRef Name) { SmallVector scratch; StringRef blobData; - unsigned kind = SILCursor.readRecord(entry.ID, scratch, &blobData); + llvm::Expected maybeKind = + SILCursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + unsigned kind = maybeKind.get(); assert(kind == SIL_GLOBALVAR && "expect a sil global var"); (void)kind; @@ -2675,7 +2724,7 @@ void SILDeserializer::getAllSILFunctions() { false/*errorIfEmptyBody*/); if (!maybeFunc) { // Ignore the error; treat it as if we didn't have a definition. - llvm::consumeError(maybeFunc.takeError()); + consumeError(maybeFunc.takeError()); } } } @@ -2690,8 +2739,13 @@ SILVTable *SILDeserializer::readVTable(DeclID VId) { return vTableOrOffset; BCOffsetRAII restoreOffset(SILCursor); - SILCursor.JumpToBit(vTableOrOffset); - auto entry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (llvm::Error Err = SILCursor.JumpToBit(vTableOrOffset)) + MF->fatal(std::move(Err)); + llvm::Expected maybeEntry = + SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::Error) { LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in readVTable.\n"); return nullptr; @@ -2699,7 +2753,11 @@ SILVTable *SILDeserializer::readVTable(DeclID VId) { SmallVector scratch; StringRef blobData; - unsigned kind = SILCursor.readRecord(entry.ID, scratch, &blobData); + llvm::Expected maybeKind = + SILCursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + unsigned kind = maybeKind.get(); assert(kind == SIL_VTABLE && "expect a sil vtable"); (void)kind; @@ -2717,11 +2775,17 @@ SILVTable *SILDeserializer::readVTable(DeclID VId) { // Fetch the next record. scratch.clear(); - entry = SILCursor.advance(AF_DontPopBlockAtEnd); + maybeEntry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::EndBlock) // This vtable has no contents. return nullptr; - kind = SILCursor.readRecord(entry.ID, scratch); + maybeKind = SILCursor.readRecord(entry.ID, scratch); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + kind = maybeKind.get(); std::vector vtableEntries; // Another SIL_VTABLE record means the end of this VTable. @@ -2747,11 +2811,17 @@ SILVTable *SILDeserializer::readVTable(DeclID VId) { // Fetch the next record. scratch.clear(); - entry = SILCursor.advance(AF_DontPopBlockAtEnd); + maybeEntry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::EndBlock) // EndBlock means the end of this VTable. break; - kind = SILCursor.readRecord(entry.ID, scratch); + maybeKind = SILCursor.readRecord(entry.ID, scratch); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + kind = maybeKind.get(); } // If we've already serialized the module, don't mark the witness table @@ -2797,8 +2867,13 @@ SILProperty *SILDeserializer::readProperty(DeclID PId) { return propOrOffset.get(); BCOffsetRAII restoreOffset(SILCursor); - SILCursor.JumpToBit(propOrOffset.getOffset()); - auto entry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (llvm::Error Err = SILCursor.JumpToBit(propOrOffset.getOffset())) + MF->fatal(std::move(Err)); + llvm::Expected maybeEntry = + SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::Error) { LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in readProperty.\n"); return nullptr; @@ -2806,7 +2881,11 @@ SILProperty *SILDeserializer::readProperty(DeclID PId) { SmallVector scratch; StringRef blobData; - unsigned kind = SILCursor.readRecord(entry.ID, scratch, &blobData); + llvm::Expected maybeKind = + SILCursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + unsigned kind = maybeKind.get(); assert(kind == SIL_PROPERTY && "expect a sil_property"); (void)kind; @@ -2836,7 +2915,10 @@ void SILDeserializer::readWitnessTableEntries( std::vector &conditionalConformances) { SmallVector scratch; - unsigned kind = SILCursor.readRecord(entry.ID, scratch); + llvm::Expected maybeKind = SILCursor.readRecord(entry.ID, scratch); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + unsigned kind = maybeKind.get(); // Another record means the end of this WitnessTable. while (kind != SIL_WITNESS_TABLE && @@ -2898,11 +2980,18 @@ void SILDeserializer::readWitnessTableEntries( // Fetch the next record. scratch.clear(); - entry = SILCursor.advance(AF_DontPopBlockAtEnd); + llvm::Expected maybeEntry = + SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::EndBlock) // EndBlock means the end of this WitnessTable. break; - kind = SILCursor.readRecord(entry.ID, scratch); + maybeKind = SILCursor.readRecord(entry.ID, scratch); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + kind = maybeKind.get(); } } @@ -2918,8 +3007,13 @@ SILWitnessTable *SILDeserializer::readWitnessTable(DeclID WId, return wTableOrOffset.get(); BCOffsetRAII restoreOffset(SILCursor); - SILCursor.JumpToBit(wTableOrOffset.getOffset()); - auto entry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (llvm::Error Err = SILCursor.JumpToBit(wTableOrOffset.getOffset())) + MF->fatal(std::move(Err)); + llvm::Expected maybeEntry = + SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::Error) { LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in readWitnessTable.\n"); return nullptr; @@ -2927,7 +3021,11 @@ SILWitnessTable *SILDeserializer::readWitnessTable(DeclID WId, SmallVector scratch; StringRef blobData; - unsigned kind = SILCursor.readRecord(entry.ID, scratch, &blobData); + llvm::Expected maybeKind = + SILCursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + unsigned kind = maybeKind.get(); assert(kind == SIL_WITNESS_TABLE && "expect a sil witnesstable"); (void)kind; @@ -2996,7 +3094,10 @@ SILWitnessTable *SILDeserializer::readWitnessTable(DeclID WId, // Fetch the next record. scratch.clear(); - entry = SILCursor.advance(AF_DontPopBlockAtEnd); + maybeEntry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::EndBlock) return nullptr; @@ -3063,8 +3164,13 @@ readDefaultWitnessTable(DeclID WId, SILDefaultWitnessTable *existingWt) { return wTableOrOffset.get(); BCOffsetRAII restoreOffset(SILCursor); - SILCursor.JumpToBit(wTableOrOffset.getOffset()); - auto entry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (llvm::Error Err = SILCursor.JumpToBit(wTableOrOffset.getOffset())) + MF->fatal(std::move(Err)); + llvm::Expected maybeEntry = + SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::Error) { LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in " "readDefaultWitnessTable.\n"); @@ -3073,7 +3179,11 @@ readDefaultWitnessTable(DeclID WId, SILDefaultWitnessTable *existingWt) { SmallVector scratch; StringRef blobData; - unsigned kind = SILCursor.readRecord(entry.ID, scratch, &blobData); + llvm::Expected maybeKind = + SILCursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) + MF->fatal(maybeKind.takeError()); + unsigned kind = maybeKind.get(); assert(kind == SIL_DEFAULT_WITNESS_TABLE && "expect a sil default witness table"); (void)kind; @@ -3123,7 +3233,10 @@ readDefaultWitnessTable(DeclID WId, SILDefaultWitnessTable *existingWt) { // Fetch the next record. scratch.clear(); - entry = SILCursor.advance(AF_DontPopBlockAtEnd); + maybeEntry = SILCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) + MF->fatal(maybeEntry.takeError()); + entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::EndBlock) return nullptr; diff --git a/lib/Serialization/ModuleFile.cpp b/lib/Serialization/ModuleFile.cpp index d5c4190d575ae..439687bf61f19 100644 --- a/lib/Serialization/ModuleFile.cpp +++ b/lib/Serialization/ModuleFile.cpp @@ -40,16 +40,31 @@ using llvm::Expected; static bool checkModuleSignature(llvm::BitstreamCursor &cursor, ArrayRef signature) { - for (unsigned char byte : signature) - if (cursor.AtEndOfStream() || cursor.Read(8) != byte) + for (unsigned char byte : signature) { + if (cursor.AtEndOfStream()) return false; + if (Expected maybeRead = + cursor.Read(8)) { + if (maybeRead.get() != byte) + return false; + } else { + consumeError(maybeRead.takeError()); + return false; + } + } return true; } static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor, unsigned ID, bool shouldReadBlockInfo = true) { - auto next = cursor.advance(); + Expected maybeNext = cursor.advance(); + if (!maybeNext) { + // FIXME this drops the error on the floor. + consumeError(maybeNext.takeError()); + return false; + } + llvm::BitstreamEntry next = maybeNext.get(); if (next.Kind != llvm::BitstreamEntry::SubBlock) return false; @@ -68,7 +83,12 @@ static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor, if (next.ID != ID) return false; - cursor.EnterSubBlock(ID); + if (llvm::Error Err = cursor.EnterSubBlock(ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + return false; + } + return true; } @@ -79,7 +99,13 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor, SmallVectorImpl &scratch, ExtendedValidationInfo &extendedInfo) { while (!cursor.AtEndOfStream()) { - auto entry = cursor.advance(); + Expected maybeEntry = cursor.advance(); + if (!maybeEntry) { + // FIXME this drops the error on the floor. + consumeError(maybeEntry.takeError()); + return false; + } + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::EndBlock) break; @@ -96,7 +122,14 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor, scratch.clear(); StringRef blobData; - unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData); + Expected maybeKind = + cursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) { + // FIXME this drops the error on the floor. + consumeError(maybeKind.takeError()); + return false; + } + unsigned kind = maybeKind.get(); switch (kind) { case options_block::SDK_PATH: extendedInfo.setSDKPath(blobData); @@ -141,7 +174,14 @@ validateControlBlock(llvm::BitstreamCursor &cursor, bool versionSeen = false; while (!cursor.AtEndOfStream()) { - auto entry = cursor.advance(); + Expected maybeEntry = cursor.advance(); + if (!maybeEntry) { + // FIXME this drops the error on the floor. + consumeError(maybeEntry.takeError()); + result.status = Status::Malformed; + return result; + } + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::EndBlock) break; @@ -152,7 +192,12 @@ validateControlBlock(llvm::BitstreamCursor &cursor, if (entry.Kind == llvm::BitstreamEntry::SubBlock) { if (entry.ID == OPTIONS_BLOCK_ID && extendedInfo) { - cursor.EnterSubBlock(OPTIONS_BLOCK_ID); + if (llvm::Error Err = cursor.EnterSubBlock(OPTIONS_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + result.status = Status::Malformed; + return result; + } if (!readOptionsBlock(cursor, scratch, *extendedInfo)) { result.status = Status::Malformed; return result; @@ -170,7 +215,15 @@ validateControlBlock(llvm::BitstreamCursor &cursor, scratch.clear(); StringRef blobData; - unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData); + Expected maybeKind = + cursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) { + // FIXME this drops the error on the floor. + consumeError(maybeKind.takeError()); + result.status = Status::Malformed; + return result; + } + unsigned kind = maybeKind.get(); switch (kind) { case control_block::METADATA: { if (versionSeen) { @@ -243,7 +296,13 @@ static bool validateInputBlock( SmallString<256> dependencyFullPathBuffer; while (!cursor.AtEndOfStream()) { - auto entry = cursor.advance(); + Expected maybeEntry = cursor.advance(); + if (!maybeEntry) { + // FIXME this drops the error on the floor. + consumeError(maybeEntry.takeError()); + return true; + } + llvm::BitstreamEntry entry = maybeEntry.get(); if (entry.Kind == llvm::BitstreamEntry::EndBlock) break; @@ -252,7 +311,14 @@ static bool validateInputBlock( scratch.clear(); StringRef blobData; - unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData); + Expected maybeKind = + cursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) { + // FIXME this drops the error on the floor. + consumeError(maybeKind.takeError()); + return true; + } + unsigned kind = maybeKind.get(); switch (kind) { case input_block::FILE_DEPENDENCY: { bool isHashBased = scratch[2] != 0; @@ -319,12 +385,25 @@ ValidationInfo serialization::validateSerializedAST( llvm::BitstreamEntry topLevelEntry; while (!cursor.AtEndOfStream()) { - topLevelEntry = cursor.advance(AF_DontPopBlockAtEnd); + Expected maybeEntry = + cursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) { + // FIXME this drops the error on the floor. + consumeError(maybeEntry.takeError()); + result.status = Status::Malformed; + return result; + } + topLevelEntry = maybeEntry.get(); if (topLevelEntry.Kind != llvm::BitstreamEntry::SubBlock) break; if (topLevelEntry.ID == CONTROL_BLOCK_ID) { - cursor.EnterSubBlock(CONTROL_BLOCK_ID); + if (llvm::Error Err = cursor.EnterSubBlock(CONTROL_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + result.status = Status::Malformed; + return result; + } result = validateControlBlock(cursor, scratch, {SWIFTMODULE_VERSION_MAJOR, SWIFTMODULE_VERSION_MINOR}, @@ -334,7 +413,12 @@ ValidationInfo serialization::validateSerializedAST( } else if (dependencies && result.status == Status::Valid && topLevelEntry.ID == INPUT_BLOCK_ID) { - cursor.EnterSubBlock(INPUT_BLOCK_ID); + if (llvm::Error Err = cursor.EnterSubBlock(INPUT_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + result.status = Status::Malformed; + return result; + } if (validateInputBlock(cursor, scratch, *dependencies)) { result.status = Status::Malformed; return result; @@ -829,13 +913,23 @@ ModuleFile::readObjCMethodTable(ArrayRef fields, StringRef blobData) { } bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) { - cursor.EnterSubBlock(INDEX_BLOCK_ID); + if (llvm::Error Err = cursor.EnterSubBlock(INDEX_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + return false; + } SmallVector scratch; StringRef blobData; while (!cursor.AtEndOfStream()) { - auto entry = cursor.advance(); + Expected maybeEntry = cursor.advance(); + if (!maybeEntry) { + // FIXME this drops the error on the floor. + consumeError(maybeEntry.takeError()); + return false; + } + llvm::BitstreamEntry entry = maybeEntry.get(); switch (entry.Kind) { case llvm::BitstreamEntry::EndBlock: return true; @@ -846,13 +940,25 @@ bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) { case llvm::BitstreamEntry::SubBlock: if (entry.ID == DECL_MEMBER_TABLES_BLOCK_ID) { DeclMemberTablesCursor = cursor; - DeclMemberTablesCursor.EnterSubBlock(DECL_MEMBER_TABLES_BLOCK_ID); + if (llvm::Error Err = DeclMemberTablesCursor.EnterSubBlock( + DECL_MEMBER_TABLES_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + return false; + } llvm::BitstreamEntry subentry; do { // Scan forward, to load the cursor with any abbrevs we'll need while // seeking inside this block later. - subentry = DeclMemberTablesCursor.advance( - llvm::BitstreamCursor::AF_DontPopBlockAtEnd); + Expected maybeEntry = + DeclMemberTablesCursor.advance( + llvm::BitstreamCursor::AF_DontPopBlockAtEnd); + if (!maybeEntry) { + // FIXME this drops the error on the floor. + consumeError(maybeEntry.takeError()); + return false; + } + subentry = maybeEntry.get(); } while (!DeclMemberTablesCursor.AtEndOfStream() && subentry.Kind != llvm::BitstreamEntry::Record && subentry.Kind != llvm::BitstreamEntry::EndBlock); @@ -864,7 +970,14 @@ bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) { case llvm::BitstreamEntry::Record: scratch.clear(); blobData = {}; - unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData); + Expected maybeKind = + cursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) { + // FIXME this drops the error on the floor. + consumeError(maybeKind.takeError()); + return false; + } + unsigned kind = maybeKind.get(); switch (kind) { case index_block::DECL_OFFSETS: @@ -1055,13 +1168,23 @@ ModuleFile::readGroupTable(ArrayRef Fields, StringRef BlobData) { } bool ModuleFile::readCommentBlock(llvm::BitstreamCursor &cursor) { - cursor.EnterSubBlock(COMMENT_BLOCK_ID); + if (llvm::Error Err = cursor.EnterSubBlock(COMMENT_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + return false; + } SmallVector scratch; StringRef blobData; while (!cursor.AtEndOfStream()) { - auto entry = cursor.advance(); + Expected maybeEntry = cursor.advance(); + if (!maybeEntry) { + // FIXME this drops the error on the floor. + consumeError(maybeEntry.takeError()); + return false; + } + llvm::BitstreamEntry entry = maybeEntry.get(); switch (entry.Kind) { case llvm::BitstreamEntry::EndBlock: return true; @@ -1077,7 +1200,14 @@ bool ModuleFile::readCommentBlock(llvm::BitstreamCursor &cursor) { case llvm::BitstreamEntry::Record: scratch.clear(); - unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData); + Expected maybeKind = + cursor.readRecord(entry.ID, scratch, &blobData); + if (!maybeKind) { + // FIXME this drops the error on the floor. + consumeError(maybeKind.takeError()); + return false; + } + unsigned kind = maybeKind.get(); switch (kind) { case comment_block::DECL_COMMENTS: @@ -1192,13 +1322,24 @@ bool ModuleFile::readModuleDocIfPresent() { ValidationInfo info; while (!docCursor.AtEndOfStream()) { - topLevelEntry = docCursor.advance(AF_DontPopBlockAtEnd); + Expected maybeEntry = + docCursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) { + // FIXME this drops the error on the floor. + consumeError(maybeEntry.takeError()); + return false; + } + topLevelEntry = maybeEntry.get(); if (topLevelEntry.Kind != llvm::BitstreamEntry::SubBlock) break; switch (topLevelEntry.ID) { case CONTROL_BLOCK_ID: { - docCursor.EnterSubBlock(CONTROL_BLOCK_ID); + if (llvm::Error Err = docCursor.EnterSubBlock(CONTROL_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + return false; + } info = validateControlBlock(docCursor, scratch, {SWIFTDOC_VERSION_MAJOR, @@ -1263,13 +1404,26 @@ ModuleFile::ModuleFile( llvm::BitstreamEntry topLevelEntry; while (!cursor.AtEndOfStream()) { - topLevelEntry = cursor.advance(AF_DontPopBlockAtEnd); + Expected maybeEntry = + cursor.advance(AF_DontPopBlockAtEnd); + if (!maybeEntry) { + // FIXME this drops the error diagnostic on the floor. + consumeError(maybeEntry.takeError()); + error(); + return; + } + topLevelEntry = maybeEntry.get(); if (topLevelEntry.Kind != llvm::BitstreamEntry::SubBlock) break; switch (topLevelEntry.ID) { case CONTROL_BLOCK_ID: { - cursor.EnterSubBlock(CONTROL_BLOCK_ID); + if (llvm::Error Err = cursor.EnterSubBlock(CONTROL_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + error(); + return; + } info = validateControlBlock(cursor, scratch, {SWIFTMODULE_VERSION_MAJOR, @@ -1294,13 +1448,33 @@ ModuleFile::ModuleFile( return; } - cursor.EnterSubBlock(INPUT_BLOCK_ID); + if (llvm::Error Err = cursor.EnterSubBlock(INPUT_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + error(); + return; + } - auto next = cursor.advance(); + Expected maybeNext = cursor.advance(); + if (!maybeNext) { + // FIXME this drops the error on the floor. + consumeError(maybeNext.takeError()); + error(); + return; + } + llvm::BitstreamEntry next = maybeNext.get(); while (next.Kind == llvm::BitstreamEntry::Record) { scratch.clear(); StringRef blobData; - unsigned kind = cursor.readRecord(next.ID, scratch, &blobData); + Expected maybeKind = + cursor.readRecord(next.ID, scratch, &blobData); + if (!maybeKind) { + // FIXME this drops the error on the floor. + consumeError(maybeKind.takeError()); + error(); + return; + } + unsigned kind = maybeKind.get(); switch (kind) { case input_block::IMPORTED_MODULE: { unsigned rawImportControl; @@ -1363,7 +1537,14 @@ ModuleFile::ModuleFile( break; } - next = cursor.advance(); + maybeNext = cursor.advance(); + if (!maybeNext) { + // FIXME this drops the error on the floor. + consumeError(maybeNext.takeError()); + error(); + return; + } + next = maybeNext.get(); } if (next.Kind != llvm::BitstreamEntry::EndBlock) @@ -1381,8 +1562,22 @@ ModuleFile::ModuleFile( // The decls-and-types block is lazily loaded. Save the cursor and load // any abbrev records at the start of the block. DeclTypeCursor = cursor; - DeclTypeCursor.EnterSubBlock(DECLS_AND_TYPES_BLOCK_ID); - if (DeclTypeCursor.advance().Kind == llvm::BitstreamEntry::Error) + if (llvm::Error Err = + DeclTypeCursor.EnterSubBlock(DECLS_AND_TYPES_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + error(); + return; + } + + Expected maybeCursor = DeclTypeCursor.advance(); + if (!maybeCursor) { + // FIXME this drops the error on the floor. + consumeError(maybeCursor.takeError()); + error(); + return; + } + if (maybeCursor.get().Kind == llvm::BitstreamEntry::Error) error(); // With the main cursor, skip over the block and continue. @@ -1399,13 +1594,34 @@ ModuleFile::ModuleFile( return; } - cursor.EnterSubBlock(IDENTIFIER_DATA_BLOCK_ID); + if (llvm::Error Err = cursor.EnterSubBlock(IDENTIFIER_DATA_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + error(); + return; + } - auto next = cursor.advanceSkippingSubblocks(); + Expected maybeNext = + cursor.advanceSkippingSubblocks(); + if (!maybeNext) { + // FIXME this drops the error on the floor. + consumeError(maybeNext.takeError()); + error(); + return; + } + llvm::BitstreamEntry next = maybeNext.get(); while (next.Kind == llvm::BitstreamEntry::Record) { scratch.clear(); StringRef blobData; - unsigned kind = cursor.readRecord(next.ID, scratch, &blobData); + Expected maybeKind = + cursor.readRecord(next.ID, scratch, &blobData); + if (!maybeKind) { + // FIXME this drops the error on the floor. + consumeError(maybeKind.takeError()); + error(); + return; + } + unsigned kind = maybeKind.get(); switch (kind) { case identifier_block::IDENTIFIER_DATA: @@ -1418,7 +1634,14 @@ ModuleFile::ModuleFile( break; } - next = cursor.advanceSkippingSubblocks(); + maybeNext = cursor.advanceSkippingSubblocks(); + if (!maybeNext) { + // FIXME this drops the error on the floor. + consumeError(maybeNext.takeError()); + error(); + return; + } + next = maybeNext.get(); } if (next.Kind != llvm::BitstreamEntry::EndBlock) { @@ -1440,7 +1663,12 @@ ModuleFile::ModuleFile( case SIL_INDEX_BLOCK_ID: { // Save the cursor. SILIndexCursor = cursor; - SILIndexCursor.EnterSubBlock(SIL_INDEX_BLOCK_ID); + if (llvm::Error Err = SILIndexCursor.EnterSubBlock(SIL_INDEX_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + error(); + return; + } // With the main cursor, skip over the block and continue. if (cursor.SkipBlock()) { @@ -1453,7 +1681,12 @@ ModuleFile::ModuleFile( case SIL_BLOCK_ID: { // Save the cursor. SILCursor = cursor; - SILCursor.EnterSubBlock(SIL_BLOCK_ID); + if (llvm::Error Err = SILCursor.EnterSubBlock(SIL_BLOCK_ID)) { + // FIXME this drops the error on the floor. + consumeError(std::move(Err)); + error(); + return; + } // With the main cursor, skip over the block and continue. if (cursor.SkipBlock()) { @@ -1996,16 +2229,17 @@ ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclBaseName N, DeclMembersTables[subTableOffset]; if (!subTable) { BCOffsetRAII restoreOffset(DeclMemberTablesCursor); - DeclMemberTablesCursor.JumpToBit(subTableOffset); - auto entry = DeclMemberTablesCursor.advance(); + fatalIfNotSuccess(DeclMemberTablesCursor.JumpToBit(subTableOffset)); + llvm::BitstreamEntry entry = + fatalIfUnexpected(DeclMemberTablesCursor.advance()); if (entry.Kind != llvm::BitstreamEntry::Record) { error(); return None; } SmallVector scratch; StringRef blobData; - unsigned kind = DeclMemberTablesCursor.readRecord(entry.ID, scratch, - &blobData); + unsigned kind = fatalIfUnexpected( + DeclMemberTablesCursor.readRecord(entry.ID, scratch, &blobData)); assert(kind == decl_member_tables_block::DECL_MEMBERS); (void)kind; subTable = readDeclMembersTable(scratch, blobData); @@ -2024,7 +2258,7 @@ ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclBaseName N, } else { if (!getContext().LangOpts.EnableDeserializationRecovery) fatal(mem.takeError()); - llvm::consumeError(mem.takeError()); + consumeError(mem.takeError()); // Treat this as a cache-miss to the caller and let them attempt // to refill through the normal loadAllMembers() path. @@ -2151,7 +2385,7 @@ void ModuleFile::getTopLevelDecls(SmallVectorImpl &results) { if (!declOrError) { if (!getContext().LangOpts.EnableDeserializationRecovery) fatal(declOrError.takeError()); - llvm::consumeError(declOrError.takeError()); + consumeError(declOrError.takeError()); continue; } results.push_back(declOrError.get()); diff --git a/tools/driver/modulewrap_main.cpp b/tools/driver/modulewrap_main.cpp index 3f0025c806124..2c2a5366a5946 100644 --- a/tools/driver/modulewrap_main.cpp +++ b/tools/driver/modulewrap_main.cpp @@ -148,9 +148,20 @@ int modulewrap_main(ArrayRef Args, const char *Argv0, // Superficially verify that the input is a swift module file. llvm::BitstreamCursor Cursor(ErrOrBuf.get()->getMemBufferRef()); for (unsigned char Byte : serialization::SWIFTMODULE_SIGNATURE) - if (Cursor.AtEndOfStream() || Cursor.Read(8) != Byte) { + if (Cursor.AtEndOfStream()) { Instance.getDiags().diagnose(SourceLoc(), diag::error_parse_input_file, - Filename, "signature mismatch"); + Filename, + "signature mismatch, end of stream"); + return 1; + } else if (llvm::Expected MaybeRead = Cursor.Read(8)) { + if (MaybeRead.get() != Byte) { + Instance.getDiags().diagnose(SourceLoc(), diag::error_parse_input_file, + Filename, "signature mismatch"); + return 1; + } + } else { + Instance.getDiags().diagnose(SourceLoc(), diag::error_parse_input_file, + Filename, toString(MaybeRead.takeError())); return 1; } From 1cd8e193579f13365ba25f48baccbb70abd6f0f1 Mon Sep 17 00:00:00 2001 From: Francis Visoiu Mistrih Date: Wed, 3 Jul 2019 14:27:04 -0700 Subject: [PATCH 003/115] [Bitcode] Update includes: llvm/Bitcode -> llvm/Bitstream The Bitstream part of Bitcode moved to llvm/Bitstream in LLVM. This updates the uses in swift. See r365091 [Bitcode] Move Bitstream to a separate library. --- include/swift/Serialization/BCReadingExtras.h | 2 +- include/swift/Serialization/ModuleFile.h | 2 +- include/swift/Serialization/ModuleFormat.h | 2 +- lib/ClangImporter/SwiftLookupTable.cpp | 4 ++-- lib/Frontend/SerializedDiagnosticConsumer.cpp | 2 +- lib/Serialization/Serialization.cpp | 2 +- tools/driver/modulewrap_main.cpp | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/swift/Serialization/BCReadingExtras.h b/include/swift/Serialization/BCReadingExtras.h index b09ca4b52b932..928a2cb82580b 100644 --- a/include/swift/Serialization/BCReadingExtras.h +++ b/include/swift/Serialization/BCReadingExtras.h @@ -13,7 +13,7 @@ #ifndef SWIFT_SERIALIZATION_BCREADINGEXTRAS_H #define SWIFT_SERIALIZATION_BCREADINGEXTRAS_H -#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Bitstream/BitstreamReader.h" namespace swift { namespace serialization { diff --git a/include/swift/Serialization/ModuleFile.h b/include/swift/Serialization/ModuleFile.h index ec1db7ff8ed45..90f584b970a02 100644 --- a/include/swift/Serialization/ModuleFile.h +++ b/include/swift/Serialization/ModuleFile.h @@ -25,7 +25,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/TinyPtrVector.h" -#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Bitstream/BitstreamReader.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" diff --git a/include/swift/Serialization/ModuleFormat.h b/include/swift/Serialization/ModuleFormat.h index 501514650f58e..6d103f5c4c186 100644 --- a/include/swift/Serialization/ModuleFormat.h +++ b/include/swift/Serialization/ModuleFormat.h @@ -22,7 +22,7 @@ #include "swift/AST/Decl.h" #include "swift/AST/Types.h" #include "llvm/Bitcode/RecordLayout.h" -#include "llvm/Bitcode/BitCodes.h" +#include "llvm/Bitstream/BitCodes.h" #include "llvm/ADT/PointerEmbeddedInt.h" namespace swift { diff --git a/lib/ClangImporter/SwiftLookupTable.cpp b/lib/ClangImporter/SwiftLookupTable.cpp index fdd9be0205f7c..82ea86b47946c 100644 --- a/lib/ClangImporter/SwiftLookupTable.cpp +++ b/lib/ClangImporter/SwiftLookupTable.cpp @@ -30,9 +30,9 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Bitcode/BitstreamReader.h" -#include "llvm/Bitcode/BitstreamWriter.h" #include "llvm/Bitcode/RecordLayout.h" +#include "llvm/Bitstream/BitstreamReader.h" +#include "llvm/Bitstream/BitstreamWriter.h" #include "llvm/Support/DJB.h" #include "llvm/Support/OnDiskHashTable.h" diff --git a/lib/Frontend/SerializedDiagnosticConsumer.cpp b/lib/Frontend/SerializedDiagnosticConsumer.cpp index e46badadfa550..5a8253bd88ed3 100644 --- a/lib/Frontend/SerializedDiagnosticConsumer.cpp +++ b/lib/Frontend/SerializedDiagnosticConsumer.cpp @@ -28,7 +28,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Bitcode/BitstreamWriter.h" +#include "llvm/Bitstream/BitstreamWriter.h" // For constant values only. #include "clang/Frontend/SerializedDiagnosticPrinter.h" diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 0c50334ca9641..56d89ec03eca7 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -42,8 +42,8 @@ #include "swift/Strings.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Bitcode/BitstreamWriter.h" #include "llvm/Bitcode/RecordLayout.h" +#include "llvm/Bitstream/BitstreamWriter.h" #include "llvm/Config/config.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Chrono.h" diff --git a/tools/driver/modulewrap_main.cpp b/tools/driver/modulewrap_main.cpp index 2c2a5366a5946..f4f9d8bdb3e32 100644 --- a/tools/driver/modulewrap_main.cpp +++ b/tools/driver/modulewrap_main.cpp @@ -26,7 +26,7 @@ #include "swift/SIL/SILModule.h" #include "swift/Subsystems.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Bitstream/BitstreamReader.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/Option.h" #include "llvm/Support/FileSystem.h" From d534de54925c78aedefa6fa7b4e48088f9c2c46c Mon Sep 17 00:00:00 2001 From: Stefan Graenitz Date: Wed, 10 Jul 2019 18:58:48 +0200 Subject: [PATCH 004/115] [CMake] Fix linux cache name: Apple-lldb-Linux.cmake --- utils/build-script-impl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/build-script-impl b/utils/build-script-impl index 2c0d7ef3305d2..85f4cbdb1d3e0 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -2533,7 +2533,7 @@ for host in "${ALL_HOSTS[@]}"; do if [[ "$(uname -s)" == "Darwin" ]] ; then cmake_cache="Apple-lldb-macOS.cmake" else - cmake_cache="Apple-lldb-linux.cmake" + cmake_cache="Apple-lldb-Linux.cmake" fi cmake_options=( From 059736e69e1e638f0e1a726b3233a638852c03fd Mon Sep 17 00:00:00 2001 From: pschuh Date: Fri, 12 Jul 2019 10:23:02 -0700 Subject: [PATCH 005/115] Fix typo introduced in PR #25845. (#26103) --- lib/Serialization/Deserialization.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 5c112f0d9b280..1dba3a15df767 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -724,7 +724,7 @@ void ModuleFile::readGenericRequirements( scratch.clear(); unsigned recordID = fatalIfUnexpected( - DeclTypeCursor.readRecord(entry.ID, scratch, &blobData)); + Cursor.readRecord(entry.ID, scratch, &blobData)); switch (recordID) { case GENERIC_REQUIREMENT: { uint8_t rawKind; From 913977bfb1ac07c1e8f8fe24a757c758371289e8 Mon Sep 17 00:00:00 2001 From: Puyan Lotfi Date: Fri, 12 Jul 2019 11:53:56 -0700 Subject: [PATCH 006/115] Updating usage of SanitizerCoverage. --- lib/IRGen/IRGen.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index b91c9e7fc4880..719c7377c5930 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -71,6 +71,7 @@ #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Instrumentation/AddressSanitizer.h" +#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" #include "llvm/Transforms/ObjCARC.h" @@ -139,7 +140,9 @@ static void addSanitizerCoveragePass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { const PassManagerBuilderWrapper &BuilderWrapper = static_cast(Builder); - PM.add(createSanitizerCoverageModulePass( + PM.add(createModuleSanitizerCoverageLegacyPassPass( + BuilderWrapper.IRGOpts.SanitizeCoverage)); + PM.add(createSanitizerCoverageLegacyPassPass( BuilderWrapper.IRGOpts.SanitizeCoverage)); } From ede421e5f4496a526f4e6167c470b0f31ffcad9c Mon Sep 17 00:00:00 2001 From: Puyan Lotfi Date: Tue, 16 Jul 2019 00:03:49 -0700 Subject: [PATCH 007/115] Adding fs::convertFDToNativeFile conversion to FileSystem.cpp. --- lib/Basic/FileSystem.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Basic/FileSystem.cpp b/lib/Basic/FileSystem.cpp index 901f2b02dae14..f357f37c5388b 100644 --- a/lib/Basic/FileSystem.cpp +++ b/lib/Basic/FileSystem.cpp @@ -197,16 +197,16 @@ std::error_code swift::moveFileIfDifferent(const llvm::Twine &source, same = true; } else { std::error_code sourceRegionErr; - fs::mapped_file_region sourceRegion(sourceFile.fd, - fs::mapped_file_region::readonly, - size, 0, sourceRegionErr); + fs::mapped_file_region sourceRegion( + fs::convertFDToNativeFile(sourceFile.fd), + fs::mapped_file_region::readonly, size, 0, sourceRegionErr); if (sourceRegionErr) return sourceRegionErr; std::error_code destRegionErr; - fs::mapped_file_region destRegion(destFile.fd, - fs::mapped_file_region::readonly, - size, 0, destRegionErr); + fs::mapped_file_region destRegion(fs::convertFDToNativeFile(destFile.fd), + fs::mapped_file_region::readonly, size, + 0, destRegionErr); if (!destRegionErr) { same = (0 == memcmp(sourceRegion.const_data(), destRegion.const_data(), From d4af68c2342fcc35dba500737cb626fdb9aba99e Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 16 Jul 2019 15:17:02 -0700 Subject: [PATCH 008/115] Revert "Updating usage of SanitizerCoverage." This reverts commit 913977bfb1ac07c1e8f8fe24a757c758371289e8. SVN r366153 reverts the necessary LLVM changes. --- lib/IRGen/IRGen.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index 719c7377c5930..b91c9e7fc4880 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -71,7 +71,6 @@ #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Instrumentation/AddressSanitizer.h" -#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" #include "llvm/Transforms/ObjCARC.h" @@ -140,9 +139,7 @@ static void addSanitizerCoveragePass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { const PassManagerBuilderWrapper &BuilderWrapper = static_cast(Builder); - PM.add(createModuleSanitizerCoverageLegacyPassPass( - BuilderWrapper.IRGOpts.SanitizeCoverage)); - PM.add(createSanitizerCoverageLegacyPassPass( + PM.add(createSanitizerCoverageModulePass( BuilderWrapper.IRGOpts.SanitizeCoverage)); } From 2d8cf9d5bc94cdb75d80643710a090198fd44a7d Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 16 Jul 2019 13:37:27 -0700 Subject: [PATCH 009/115] build: explicitly specify the python path This ensures that we use python 2.7 when building LLVM. The LLVM tooling has not yet been ported to python 3, and this breaks the CI builds which are now finding python 3 via `PATH`. --- utils/build-script-impl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/utils/build-script-impl b/utils/build-script-impl index cbe4a60a06c9e..cf10c6d45edb9 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -669,6 +669,10 @@ function set_build_options_for_host() { -DCOMPILER_RT_ENABLE_TVOS:BOOL=FALSE -DSANITIZER_MIN_OSX_VERSION="${cmake_osx_deployment_target}" -DLLVM_ENABLE_MODULES:BOOL="$(true_false ${LLVM_ENABLE_MODULES})" + # NOTE(compnerd) this explicitly sets up the python executable + # since we sometimes end up with python 3 and the tooling + # currently relies on python 2.7 + -DPYTHON_EXECUTABLE:PATH=/usr/bin/python2.7 ) if [[ $(is_llvm_lto_enabled) == "TRUE" ]]; then if [[ $(cmake_needs_to_specify_standard_computed_defaults) == "TRUE" ]]; then @@ -2558,6 +2562,21 @@ for host in "${ALL_HOSTS[@]}"; do cmake_options+=( -DLLDB_CODESIGN_IDENTITY="" -DLLDB_USE_SYSTEM_DEBUGSERVER:BOOL="${LLDB_USE_SYSTEM_DEBUGSERVER}" + + # NOTE(compnerd) this explicitly sets up the python + # executable since we sometimes end up with python 3 and + # the tooling currently relies on python 2.7 + -DPython_ADDITIONAL_VERSIONS="2.7" + -DPYTHON_EXECUTABLE:PATH=/usr/bin/python2.7 + -DPYTHON_LIBRARY="$(xcrun --sdk ${xcrun_sdk_name} --show-sdk-path)/System/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.tbd" + -DPYTHON_INCLUDE_DIR="$(xcrun --sdk ${xcrun_sdk_name} --show-sdk-path)/System/Library/Frameworks/Python.framework/Headers" + ) + else + cmake_options+=( + # NOTE(compnerd) this explicitly sets up the python + # executable since we sometimes end up with python 3 and + # the tooling currently relies on python 2.7 + -DPYTHON_EXECUTABLE:PATH=/usr/bin/python2.7 ) fi fi From 94ef5431ffc5b9c4fe1f70f64305c3612c97e252 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 18 Jul 2019 16:28:15 -0700 Subject: [PATCH 010/115] Merge Swift & Clang VFS in the ClangImporter The clang importer has to deal with two virtual file systems, one coming from clang, and one coming from swift. Currently, if both are set, we emit a diagnostic that we'll pick the swift one. This commit changes that, by merging the two virtual file systems. The motivation for this change is the reproducer infrastructure in LLDB, which adds a third virtual file system to the mix. --- include/swift/AST/DiagnosticsClangImporter.def | 4 ---- .../swift/ClangImporter/ClangImporterOptions.h | 4 ---- lib/ClangImporter/ClangImporter.cpp | 15 ++++----------- lib/Frontend/Frontend.cpp | 3 --- test/Frontend/Inputs/vfs/a-modulemap | 4 ++++ test/Frontend/Inputs/vfs/b-header | 1 + .../Inputs/vfs/quaternary-vfsoverlay.yaml | 17 +++++++++++++++++ test/Frontend/vfs.swift | 8 +++++--- .../SourceKit/lib/SwiftLang/SwiftASTManager.cpp | 1 - .../SourceKit/lib/SwiftLang/SwiftCompletion.cpp | 1 - 10 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 test/Frontend/Inputs/vfs/b-header create mode 100644 test/Frontend/Inputs/vfs/quaternary-vfsoverlay.yaml diff --git a/include/swift/AST/DiagnosticsClangImporter.def b/include/swift/AST/DiagnosticsClangImporter.def index bad492d8f0a1e..285694e764b09 100644 --- a/include/swift/AST/DiagnosticsClangImporter.def +++ b/include/swift/AST/DiagnosticsClangImporter.def @@ -91,10 +91,6 @@ WARNING(implicit_bridging_header_imported_from_module,none, "is deprecated and will be removed in a later version of Swift", (StringRef, Identifier)) -WARNING(clang_vfs_overlay_is_ignored,none, - "ignoring '-ivfsoverlay' options provided to '-Xcc' in favor of " - "'-vfsoverlay'", ()) - #ifndef DIAG_NO_UNDEF # if defined(DIAG) # undef DIAG diff --git a/include/swift/ClangImporter/ClangImporterOptions.h b/include/swift/ClangImporter/ClangImporterOptions.h index e46a08921fad2..67399decbdc96 100644 --- a/include/swift/ClangImporter/ClangImporterOptions.h +++ b/include/swift/ClangImporter/ClangImporterOptions.h @@ -100,10 +100,6 @@ class ClangImporterOptions { /// When set, don't enforce warnings with -Werror. bool DebuggerSupport = false; - /// When set, clobber the Clang instance's virtual file system with the Swift - /// virtual file system. - bool ForceUseSwiftVirtualFileSystem = false; - /// Return a hash code of any components from these options that should /// contribute to a Swift Bridging PCH hash. llvm::hash_code getPCHHashComponents() const { diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 744b0383a40ba..8df531917d972 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -1018,17 +1018,10 @@ ClangImporter::create(ASTContext &ctx, // Set up the file manager. { - llvm::IntrusiveRefCntPtr VFS; - if (!ctx.SearchPathOpts.VFSOverlayFiles.empty() || - importerOpts.ForceUseSwiftVirtualFileSystem) { - // If the clang instance has overlays it means the user has provided - // -ivfsoverlay options. We're going to clobber their file system with - // the Swift file system, so warn about it. - if (!instance.getHeaderSearchOpts().VFSOverlayFiles.empty()) { - ctx.Diags.diagnose(SourceLoc(), diag::clang_vfs_overlay_is_ignored); - } - VFS = ctx.SourceMgr.getFileSystem(); - } + llvm::IntrusiveRefCntPtr VFS = + clang::createVFSFromCompilerInvocation(instance.getInvocation(), + instance.getDiagnostics(), + ctx.SourceMgr.getFileSystem()); instance.createFileManager(std::move(VFS)); } diff --git a/lib/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index 63c588b468b5d..f8a6ecd1a7ee7 100644 --- a/lib/Frontend/Frontend.cpp +++ b/lib/Frontend/Frontend.cpp @@ -235,9 +235,6 @@ static bool loadAndValidateVFSOverlay( const llvm::IntrusiveRefCntPtr &BaseFS, const llvm::IntrusiveRefCntPtr &OverlayFS, DiagnosticEngine &Diag) { - // FIXME: It should be possible to allow chained lookup of later VFS overlays - // through the mapping defined by earlier overlays. - // See rdar://problem/39440687 auto Buffer = BaseFS->getBufferForFile(File); if (!Buffer) { Diag.diagnose(SourceLoc(), diag::cannot_open_file, File, diff --git a/test/Frontend/Inputs/vfs/a-modulemap b/test/Frontend/Inputs/vfs/a-modulemap index 18173c43c4415..5705c8529c38c 100644 --- a/test/Frontend/Inputs/vfs/a-modulemap +++ b/test/Frontend/Inputs/vfs/a-modulemap @@ -1,3 +1,7 @@ module VFSMappedModule { header "VFSMappedModule.h" } + +module YetAnotherVFSMappedModule { + header "YetAnotherVFSMappedModule.h" +} diff --git a/test/Frontend/Inputs/vfs/b-header b/test/Frontend/Inputs/vfs/b-header new file mode 100644 index 0000000000000..1e7ef4c9ab15e --- /dev/null +++ b/test/Frontend/Inputs/vfs/b-header @@ -0,0 +1 @@ +#define MAJOR_SUCCESS 1 diff --git a/test/Frontend/Inputs/vfs/quaternary-vfsoverlay.yaml b/test/Frontend/Inputs/vfs/quaternary-vfsoverlay.yaml new file mode 100644 index 0000000000000..ad0b4c793fbdb --- /dev/null +++ b/test/Frontend/Inputs/vfs/quaternary-vfsoverlay.yaml @@ -0,0 +1,17 @@ +{ + 'version': 0, + 'use-external-names': false, + 'roots': [ + { + 'name': 'OUT_DIR', 'type': 'directory', + 'contents': [ + { 'name': 'YetAnotherVFSMappedModule.h', 'type': 'file', + 'external-contents': 'INPUT_DIR/vfs/b-header' + }, + { 'name': 'YetAnotherVFSMappedModule.framework/Headers/VFSMappedModule.h', 'type': 'file', + 'external-contents': 'INPUT_DIR/vfs/b-header' + }, + ] + }, + ] +} diff --git a/test/Frontend/vfs.swift b/test/Frontend/vfs.swift index a45c6eede956d..e8d0caf6e8ad2 100644 --- a/test/Frontend/vfs.swift +++ b/test/Frontend/vfs.swift @@ -2,6 +2,7 @@ // RUN: sed -e "s|INPUT_DIR|%/S/Inputs|g" -e "s|OUT_DIR|%/t|g" %S/Inputs/vfs/vfsoverlay.yaml > %t/overlay.yaml // RUN: sed -e "s|INPUT_DIR|%/S/Inputs|g" -e "s|OUT_DIR|%/t|g" %S/Inputs/vfs/secondary-vfsoverlay.yaml > %t/secondary-overlay.yaml // RUN: sed -e "s|INPUT_DIR|%/S/Inputs|g" -e "s|OUT_DIR|%/t|g" %S/Inputs/vfs/tertiary-vfsoverlay.yaml > %t/tertiary-overlay.yaml +// RUN: sed -e "s|INPUT_DIR|%/S/Inputs|g" -e "s|OUT_DIR|%/t|g" %S/Inputs/vfs/quaternary-vfsoverlay.yaml > %t/quaternary-vfsoverlay.yaml // RUN: not %target-swift-frontend -vfsoverlay %/t/overlay.yaml -typecheck %s %/t/mapped-file.swift -serialize-diagnostics-path %/t/basic.dia 2>&1 | %FileCheck -check-prefix=BASIC_MAPPING_ERROR %s // RUN: c-index-test -read-diagnostics %/t/basic.dia 2>&1 | %FileCheck -check-prefix=BASIC_MAPPING_ERROR %s @@ -20,10 +21,11 @@ // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %/t -DTEST_VFS_CLANG_IMPORTER -Xcc -ivfsoverlay -Xcc %/t/overlay.yaml -typecheck %/s // If we see -ivfsoverlay and -vfsoverlay, we'll clobber Clang's VFS with our own. -// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %/t -DTEST_VFS_CLANG_IMPORTER -vfsoverlay %/t/overlay.yaml -Xcc -ivfsoverlay -Xcc %/t/overlay.yaml -typecheck %/s 2>&1 | %FileCheck -check-prefix=WARN_VFS_CLOBBERED %s - -// WARN_VFS_CLOBBERED: warning: ignoring '-ivfsoverlay' options provided to '-Xcc' in favor of '-vfsoverlay' +// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %/t -DTEST_VFS_CLANG_IMPORTER -DTEST_VFS_CLANG_IMPORTER_MERGE -vfsoverlay %/t/overlay.yaml -Xcc -ivfsoverlay -Xcc %/t/quaternary-vfsoverlay.yaml -typecheck %/s 2>&1 #if TEST_VFS_CLANG_IMPORTER import VFSMappedModule +#if TEST_VFS_CLANG_IMPORTER_MERGE +import YetAnotherVFSMappedModule +#endif #endif diff --git a/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp b/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp index 0ae7f8f68e9aa..d0d577b82d299 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp @@ -950,7 +950,6 @@ ASTUnitRef ASTProducer::createASTUnit( if (fileSystem != llvm::vfs::getRealFileSystem()) { CompIns.getSourceMgr().setFileSystem(fileSystem); - Invocation.getClangImporterOptions().ForceUseSwiftVirtualFileSystem = true; } if (CompIns.setup(Invocation)) { diff --git a/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp b/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp index 651d8cbfa0a90..904b0b65f42e6 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp @@ -200,7 +200,6 @@ static bool swiftCodeCompleteImpl( if (FileSystem != llvm::vfs::getRealFileSystem()) { CI.getSourceMgr().setFileSystem(FileSystem); - Invocation.getClangImporterOptions().ForceUseSwiftVirtualFileSystem = true; } if (CI.setup(Invocation)) { From cadae2d39720153d974766d2db6f75a84772fad7 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 19 Jul 2019 14:27:38 -0700 Subject: [PATCH 011/115] Revert "build: explicitly specify the python path" --- utils/build-script-impl | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/utils/build-script-impl b/utils/build-script-impl index cf10c6d45edb9..cbe4a60a06c9e 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -669,10 +669,6 @@ function set_build_options_for_host() { -DCOMPILER_RT_ENABLE_TVOS:BOOL=FALSE -DSANITIZER_MIN_OSX_VERSION="${cmake_osx_deployment_target}" -DLLVM_ENABLE_MODULES:BOOL="$(true_false ${LLVM_ENABLE_MODULES})" - # NOTE(compnerd) this explicitly sets up the python executable - # since we sometimes end up with python 3 and the tooling - # currently relies on python 2.7 - -DPYTHON_EXECUTABLE:PATH=/usr/bin/python2.7 ) if [[ $(is_llvm_lto_enabled) == "TRUE" ]]; then if [[ $(cmake_needs_to_specify_standard_computed_defaults) == "TRUE" ]]; then @@ -2562,21 +2558,6 @@ for host in "${ALL_HOSTS[@]}"; do cmake_options+=( -DLLDB_CODESIGN_IDENTITY="" -DLLDB_USE_SYSTEM_DEBUGSERVER:BOOL="${LLDB_USE_SYSTEM_DEBUGSERVER}" - - # NOTE(compnerd) this explicitly sets up the python - # executable since we sometimes end up with python 3 and - # the tooling currently relies on python 2.7 - -DPython_ADDITIONAL_VERSIONS="2.7" - -DPYTHON_EXECUTABLE:PATH=/usr/bin/python2.7 - -DPYTHON_LIBRARY="$(xcrun --sdk ${xcrun_sdk_name} --show-sdk-path)/System/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.tbd" - -DPYTHON_INCLUDE_DIR="$(xcrun --sdk ${xcrun_sdk_name} --show-sdk-path)/System/Library/Frameworks/Python.framework/Headers" - ) - else - cmake_options+=( - # NOTE(compnerd) this explicitly sets up the python - # executable since we sometimes end up with python 3 and - # the tooling currently relies on python 2.7 - -DPYTHON_EXECUTABLE:PATH=/usr/bin/python2.7 ) fi fi From 5d0fec6e368c085c57cde43a73022b217e73be40 Mon Sep 17 00:00:00 2001 From: Puyan Lotfi Date: Mon, 22 Jul 2019 00:59:13 -0700 Subject: [PATCH 012/115] Fixing up IRGenModule to handle changes in CodeGenOptions. DisableFPElim was removed from CGO in cfe r366645. This change fixes the build for master-next. --- lib/IRGen/IRGenModule.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index eff81ce1d3cfa..5b9ccbf61e3c1 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -94,7 +94,9 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context, auto &CGO = Importer->getClangCodeGenOpts(); CGO.OptimizationLevel = Opts.shouldOptimize() ? 3 : 0; - CGO.DisableFPElim = Opts.DisableFPElim; + CGO.setFramePointer(Opts.DisableFPElim + ? clang::CodeGenOptions::FramePointerKind::All + : clang::CodeGenOptions::FramePointerKind::None); CGO.DiscardValueNames = !Opts.shouldProvideValueNames(); switch (Opts.DebugInfoLevel) { case IRGenDebugInfoLevel::None: @@ -895,12 +897,8 @@ bool swift::irgen::shouldRemoveTargetFeature(StringRef feature) { void IRGenModule::constructInitialFnAttributes(llvm::AttrBuilder &Attrs, OptimizationMode FuncOptMode) { // Add DisableFPElim. - if (!IRGen.Opts.DisableFPElim) { - Attrs.addAttribute("no-frame-pointer-elim", "false"); - } else { - Attrs.addAttribute("no-frame-pointer-elim", "true"); - Attrs.addAttribute("no-frame-pointer-elim-non-leaf"); - } + Attrs.addAttribute("frame-pointer", + IRGen.Opts.DisableFPElim ? "all" : "none"); // Add target-cpu and target-features if they are non-null. auto *Clang = static_cast(Context.getClangModuleLoader()); From 0c0c0ee7943a26c6085187eaf85944a1a097cc12 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 22 Jul 2019 13:55:08 -0700 Subject: [PATCH 013/115] [build-script] Remove support for building LLDB with Xcode --- utils/build-script | 1 - utils/build-script-impl | 252 ++++++++-------------------------------- 2 files changed, 48 insertions(+), 205 deletions(-) diff --git a/utils/build-script b/utils/build-script index 44a31ed9acdae..88441b224c49a 100755 --- a/utils/build-script +++ b/utils/build-script @@ -298,7 +298,6 @@ class BuildScriptInvocation(object): "--swift-build-type", args.swift_build_variant, "--swift-stdlib-build-type", args.swift_stdlib_build_variant, "--lldb-build-type", args.lldb_build_variant, - "--lldb-build-with-xcode", args.lldb_build_with_xcode, "--foundation-build-type", args.foundation_build_variant, "--libdispatch-build-type", args.libdispatch_build_variant, "--libicu-build-type", args.libicu_build_variant, diff --git a/utils/build-script-impl b/utils/build-script-impl index cbe4a60a06c9e..09d705f9a2b01 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -53,7 +53,6 @@ KNOWN_SETTINGS=( ninja-bin "" "the path to Ninja tool" cmark-build-type "Debug" "the CMake build variant for CommonMark (Debug, RelWithDebInfo, Release, MinSizeRel). Defaults to Debug." lldb-extra-cmake-args "" "extra command line args to pass to lldb cmake" - lldb-extra-xcodebuild-args "" "extra command line args to pass to lldb xcodebuild" lldb-test-cc "" "CC to use for building LLDB testsuite test inferiors. Defaults to just-built, in-tree clang. If set to 'host-toolchain', sets it to same as host-cc." lldb-test-with-curses "" "run test lldb test runner using curses terminal control" lldb-test-swift-only "0" "when running lldb tests, only include Swift-specific tests" @@ -74,7 +73,6 @@ KNOWN_SETTINGS=( swift-stdlib-enable-assertions "1" "enable assertions in Swift" swift-stdlib-use-nonatomic-rc "0" "build the Swift stdlib and overlays with nonatomic reference count operations enabled" lldb-build-type "Debug" "the CMake build variant for LLDB" - lldb-build-with-xcode "0" "Use xcodebuild to build LLDB, instead of CMake" llbuild-build-type "Debug" "the CMake build variant for llbuild" foundation-build-type "Debug" "the build variant for Foundation" libdispatch-build-type "Debug" "the build variant for libdispatch" @@ -1929,64 +1927,6 @@ function set_swiftevolve_build_command() { swiftevolve_build_command=("${stresstester_build_script_helper_command[@]}") } -# Construct the appropriate options to pass to an Xcode -# build of any LLDB target. -function set_lldb_xcodebuild_options() { - llvm_build_dir=$(build_directory ${host} llvm) - cmark_build_dir=$(build_directory ${host} cmark) - lldb_build_dir=$(build_directory ${host} lldb) - swift_build_dir=$(build_directory ${host} swift) - - lldb_xcodebuild_options=( - LLDB_PATH_TO_LLVM_SOURCE="${LLVM_SOURCE_DIR}" - LLDB_PATH_TO_CLANG_SOURCE="${CLANG_SOURCE_DIR}" - LLDB_PATH_TO_SWIFT_SOURCE="${SWIFT_SOURCE_DIR}" - LLDB_PATH_TO_LLVM_BUILD="${llvm_build_dir}" - LLDB_PATH_TO_CLANG_BUILD="${llvm_build_dir}" - LLDB_PATH_TO_SWIFT_BUILD="${swift_build_dir}" - LLDB_IS_BUILDBOT_BUILD="${LLDB_IS_BUILDBOT_BUILD}" - LLDB_BUILD_DATE="\"${LLDB_BUILD_DATE}\"" - SYMROOT="${lldb_build_dir}" - OBJROOT="${lldb_build_dir}" - -UseNewBuildSystem=NO - ${LLDB_EXTRA_XCODEBUILD_ARGS} - MACOSX_DEPLOYMENT_TARGET=10.13 - ) - if [[ "${LLDB_NO_DEBUGSERVER}" ]] ; then - lldb_xcodebuild_options=( - "${lldb_xcodebuild_options[@]}" - DEBUGSERVER_DISABLE_CODESIGN="1" - DEBUGSERVER_DELETE_AFTER_BUILD="1" - ) - fi - if [[ "${LLDB_USE_SYSTEM_DEBUGSERVER}" ]] ; then - lldb_xcodebuild_options=( - "${lldb_xcodebuild_options[@]}" - DEBUGSERVER_USE_FROM_SYSTEM="1" - ) - fi - if [[ "${ENABLE_ASAN}" ]] ; then - lldb_xcodebuild_options=( - "${lldb_xcodebuild_options[@]}" - ENABLE_ADDRESS_SANITIZER="YES" - -enableAddressSanitizer=YES - ) - fi - if [[ "${ENABLE_UBSAN}" ]] ; then - lldb_xcodebuild_options=( - "${lldb_xcodebuild_options[@]}" - ENABLE_UNDEFINED_BEHAVIOR_SANITIZER="YES" - -enableUndefinedBehaviorSanitizer=YES - ) - fi - if [[ "$(true_false ${LLDB_ASSERTIONS})" == "FALSE" ]]; then - lldb_xcodebuild_options=( - "${lldb_xcodebuild_options[@]}" - OTHER_CFLAGS="-DNDEBUG" - ) - fi -} - # # Configure and build each product # @@ -2517,49 +2457,36 @@ for host in "${ALL_HOSTS[@]}"; do # Get the build date LLDB_BUILD_DATE=$(date +%Y-%m-%d) - using_xcodebuild="FALSE" - if [[ "$(uname -s)" == "Darwin" && "$(true_false ${LLDB_BUILD_WITH_XCODE})" == "TRUE" ]] ; then - using_xcodebuild="TRUE" - fi - if [[ "${using_xcodebuild}" == "TRUE" ]] ; then - # Set up flags to pass to xcodebuild - set_lldb_xcodebuild_options - set_lldb_build_mode - with_pushd ${source_dir} \ - call xcodebuild -target desktop -configuration ${LLDB_BUILD_MODE} ${lldb_xcodebuild_options[@]} - continue + if [[ "$(uname -s)" == "Darwin" ]] ; then + cmake_cache="Apple-lldb-macOS.cmake" else - if [[ "$(uname -s)" == "Darwin" ]] ; then - cmake_cache="Apple-lldb-macOS.cmake" - else - cmake_cache="Apple-lldb-Linux.cmake" - fi + cmake_cache="Apple-lldb-Linux.cmake" + fi - cmake_options=( - "${cmake_options[@]}" - -C${LLDB_SOURCE_DIR}/cmake/caches/${cmake_cache} - -DCMAKE_BUILD_TYPE:STRING="${LLDB_BUILD_TYPE}" - -DLLDB_SWIFTC:PATH="$(build_directory ${LOCAL_HOST} swift)/bin/swiftc" - -DLLDB_SWIFT_LIBS:PATH="$(build_directory ${LOCAL_HOST} swift)/lib/swift" - -DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})" - -DClang_DIR:PATH=${llvm_build_dir}/lib/cmake/clang - -DLLVM_DIR:PATH=${llvm_build_dir}/lib/cmake/llvm - -DLLDB_PATH_TO_CLANG_BUILD:PATH="${llvm_build_dir}" - -DLLDB_PATH_TO_SWIFT_SOURCE:PATH="${SWIFT_SOURCE_DIR}" - -DLLDB_PATH_TO_SWIFT_BUILD:PATH="${swift_build_dir}" - -DLLDB_IS_BUILDBOT_BUILD:BOOL="${LLDB_IS_BUILDBOT_BUILD}" - -DLLDB_BUILD_DATE:STRING="\"${LLDB_BUILD_DATE}\"" - -DLLDB_ALLOW_STATIC_BINDINGS:BOOL=1 - -DLLDB_INCLUDE_TESTS:BOOL=$(false_true ${BUILD_TOOLCHAIN_ONLY}) - ) + cmake_options=( + "${cmake_options[@]}" + -C${LLDB_SOURCE_DIR}/cmake/caches/${cmake_cache} + -DCMAKE_BUILD_TYPE:STRING="${LLDB_BUILD_TYPE}" + -DLLDB_SWIFTC:PATH="$(build_directory ${LOCAL_HOST} swift)/bin/swiftc" + -DLLDB_SWIFT_LIBS:PATH="$(build_directory ${LOCAL_HOST} swift)/lib/swift" + -DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})" + -DClang_DIR:PATH=${llvm_build_dir}/lib/cmake/clang + -DLLVM_DIR:PATH=${llvm_build_dir}/lib/cmake/llvm + -DLLDB_PATH_TO_CLANG_BUILD:PATH="${llvm_build_dir}" + -DLLDB_PATH_TO_SWIFT_SOURCE:PATH="${SWIFT_SOURCE_DIR}" + -DLLDB_PATH_TO_SWIFT_BUILD:PATH="${swift_build_dir}" + -DLLDB_IS_BUILDBOT_BUILD:BOOL="${LLDB_IS_BUILDBOT_BUILD}" + -DLLDB_BUILD_DATE:STRING="\"${LLDB_BUILD_DATE}\"" + -DLLDB_ALLOW_STATIC_BINDINGS:BOOL=1 + -DLLDB_INCLUDE_TESTS:BOOL=$(false_true ${BUILD_TOOLCHAIN_ONLY}) + ) - if [[ "$(uname -s)" == "Darwin" ]] ; then - cmake_options+=( - -DLLDB_CODESIGN_IDENTITY="" - -DLLDB_USE_SYSTEM_DEBUGSERVER:BOOL="${LLDB_USE_SYSTEM_DEBUGSERVER}" - ) - fi + if [[ "$(uname -s)" == "Darwin" ]] ; then + cmake_options+=( + -DLLDB_CODESIGN_IDENTITY="" + -DLLDB_USE_SYSTEM_DEBUGSERVER:BOOL="${LLDB_USE_SYSTEM_DEBUGSERVER}" + ) fi ;; llbuild) @@ -3055,34 +2982,7 @@ for host in "${ALL_HOSTS[@]}"; do swift_build_dir=$(build_directory ${host} swift) module_cache="${build_dir}/module-cache" - using_xcodebuild="FALSE" - if [[ "$(uname -s)" == "Darwin" && "$(true_false ${LLDB_BUILD_WITH_XCODE})" == "TRUE" ]] ; then - using_xcodebuild="TRUE" - fi - - - # Run the unittests. - # FIXME: The xcode build project currently doesn't know how to run the lit style tests. - if [[ "$using_xcodebuild" == "TRUE" ]] ; then - set_lldb_xcodebuild_options - set_lldb_build_mode - # Run the LLDB unittests (gtests). - with_pushd ${LLDB_SOURCE_DIR} \ - call xcodebuild -scheme lldb-gtest -configuration ${LLDB_BUILD_MODE} ${lldb_xcodebuild_options[@]} - rc=$? - if [[ "$rc" -ne 0 ]] ; then - >&2 echo "error: LLDB gtests failed" - exit 1 - fi - fi - - # Setup lldb executable path - if [[ "$using_xcodebuild" == "TRUE" ]] ; then - lldb_executable="${lldb_build_dir}"/${LLDB_BUILD_MODE}/lldb - else - lldb_executable="${lldb_build_dir}"/bin/lldb - fi - + lldb_executable="${lldb_build_dir}"/bin/lldb results_dir="${lldb_build_dir}/test-results" # Handle test results formatter @@ -3155,10 +3055,6 @@ for host in "${ALL_HOSTS[@]}"; do fi call mkdir -p "${results_dir}" - if [[ "$using_xcodebuild" == "TRUE" ]] ; then - LLDB_DOTEST_CC_OPTS="${LLDB_DOTEST_CC_OPTS} --filecheck $(build_directory $LOCAL_HOST llvm)/bin/FileCheck --dsymutil $(build_directory $LOCAL_HOST llvm)/bin/dsymutil" - fi - # Prefer to use lldb-dotest, as building it guarantees that we build all # test dependencies. Ultimately we want to delete as much lldb-specific logic # from this file as possible and just have a single call to lldb-dotest. @@ -3168,65 +3064,32 @@ for host in "${ALL_HOSTS[@]}"; do LLVM_LIT_ARGS="${LLVM_LIT_ARGS} -j $(sysctl hw.physicalcpu | awk -v N=${BUILD_JOBS} '{ print (N < $2) ? N : $2 }')" fi - if [[ "$(true_false ${LLDB_TEST_SWIFT_ONLY})" == "TRUE" ]]; then - LLVM_LIT_ARGS="${LLVM_LIT_ARGS} --filter=[sS]wift" - fi + if [[ "$(true_false ${LLDB_TEST_SWIFT_ONLY})" == "TRUE" ]]; then + LLVM_LIT_ARGS="${LLVM_LIT_ARGS} --filter=[sS]wift" + fi # Record the times test took and report the slowest. LLVM_LIT_ARGS="${LLVM_LIT_ARGS} -v --time-tests" - if [[ "$using_xcodebuild" == "FALSE" ]] ; then - with_pushd ${lldb_build_dir} \ - call ${NINJA_BIN} -j ${BUILD_JOBS} unittests/LLDBUnitTests - with_pushd ${lldb_build_dir} \ - call ${NINJA_BIN} -j ${BUILD_JOBS} lldb-test-deps + with_pushd ${lldb_build_dir} \ + call ${NINJA_BIN} -j ${BUILD_JOBS} unittests/LLDBUnitTests + with_pushd ${lldb_build_dir} \ + call ${NINJA_BIN} -j ${BUILD_JOBS} lldb-test-deps + with_pushd ${results_dir} \ + call "${llvm_build_dir}/bin/llvm-lit" \ + "${lldb_build_dir}/lit" \ + ${LLVM_LIT_ARGS} \ + --xunit-xml-output=${results_dir}/results.xml \ + --param dotest-args="--build-dir ${lldb_build_dir}/lldb-test-build.noindex ${LLDB_TEST_SUBDIR_CLAUSE} ${LLDB_TEST_CATEGORIES} -t -E \"${DOTEST_EXTRA}\"" + if [[ -x "${LLDB_TEST_SWIFT_COMPATIBILITY}" ]] ; then + echo "Running LLDB swift compatibility tests against" \ + "${LLDB_TEST_SWIFT_COMPATIBILITY}" with_pushd ${results_dir} \ - call "${llvm_build_dir}/bin/llvm-lit" \ - "${lldb_build_dir}/lit" \ - ${LLVM_LIT_ARGS} \ - --xunit-xml-output=${results_dir}/results.xml \ - --param dotest-args="--build-dir ${lldb_build_dir}/lldb-test-build.noindex ${LLDB_TEST_SUBDIR_CLAUSE} ${LLDB_TEST_CATEGORIES} -t -E \"${DOTEST_EXTRA}\"" - if [[ -x "${LLDB_TEST_SWIFT_COMPATIBILITY}" ]] ; then - echo "Running LLDB swift compatibility tests against" \ - "${LLDB_TEST_SWIFT_COMPATIBILITY}" - with_pushd ${results_dir} \ - call "${llvm_build_dir}/bin/llvm-lit" \ - "${lldb_build_dir}/lit" \ - ${LLVM_LIT_ARGS} \ - --xunit-xml-output=${results_dir}/results.xml \ - --param dotest-args="--build-dir ${lldb_build_dir}/lldb-test-build.noindex ${LLDB_TEST_SUBDIR_CLAUSE} ${LLDB_TEST_CATEGORIES} -G swift-history --swift-compiler \"${LLDB_TEST_SWIFT_COMPATIBILITY}\" -t -E \"${DOTEST_EXTRA}\"" --filter=compat - fi - else - with_pushd "${results_dir}" \ - call env SWIFTC="$(build_directory $LOCAL_HOST swift)/bin/swiftc" \ - SWIFTLIBS="${swift_build_dir}/lib/swift" \ - "${LLDB_SOURCE_DIR}"/test/dotest.py \ - --executable "${lldb_executable}" \ - ${LLDB_TEST_DEBUG_SERVER} \ - ${LLDB_TEST_SUBDIR_CLAUSE} \ - ${LLDB_TEST_CATEGORIES} \ - ${LLDB_DOTEST_CC_OPTS} \ - ${LLDB_FORMATTER_OPTS} \ - --build-dir "${lldb_build_dir}/lldb-test-build.noindex" \ - -t -E "${DOTEST_EXTRA}" - if [[ -x "${LLDB_TEST_SWIFT_COMPATIBILITY}" ]] ; then - echo "Running LLDB swift compatibility tests against" \ - "${LLDB_TEST_SWIFT_COMPATIBILITY}" - call env SWIFTC="$(build_directory $LOCAL_HOST swift)/bin/swiftc" \ - SWIFTLIBS="${swift_build_dir}/lib/swift" \ - "${LLDB_SOURCE_DIR}"/test/dotest.py \ - --executable "${lldb_executable}" \ - ${LLDB_TEST_DEBUG_SERVER} \ - ${LLDB_TEST_SUBDIR_CLAUSE} \ - ${LLDB_TEST_CATEGORIES} \ - ${LLDB_DOTEST_CC_OPTS} \ - ${LLDB_FORMATTER_OPTS} \ - --build-dir "${lldb_build_dir}/lldb-test-build.noindex" \ - -G swift-history \ - --swift-compiler "${LLDB_TEST_SWIFT_COMPATIBILITY}" \ - -t -E "${DOTEST_EXTRA}" - fi + call "${llvm_build_dir}/bin/llvm-lit" \ + "${lldb_build_dir}/lit" \ + ${LLVM_LIT_ARGS} \ + --xunit-xml-output=${results_dir}/results.xml \ + --param dotest-args="--build-dir ${lldb_build_dir}/lldb-test-build.noindex ${LLDB_TEST_SUBDIR_CLAUSE} ${LLDB_TEST_CATEGORIES} -G swift-history --swift-compiler \"${LLDB_TEST_SWIFT_COMPATIBILITY}\" -t -E \"${DOTEST_EXTRA}\"" --filter=compat fi - continue ;; llbuild) @@ -3573,25 +3436,6 @@ for host in "${ALL_HOSTS[@]}"; do echo "--install-destdir is required to install products." exit 1 fi - if [[ "$using_xcodebuild" == "TRUE" ]] ; then - case ${host} in - linux-*) - ;; - freebsd-*) - ;; - cygwin-*) - ;; - haiku-*) - ;; - macosx-*) - set_lldb_xcodebuild_options - set_lldb_build_mode - with_pushd ${LLDB_SOURCE_DIR} \ - call xcodebuild -target toolchain -configuration ${LLDB_BUILD_MODE} install ${lldb_xcodebuild_options[@]} DSTROOT="${host_install_destdir}" LLDB_TOOLCHAIN_PREFIX="${TOOLCHAIN_PREFIX}" - continue - ;; - esac - fi ;; swiftpm) if [[ -z "${INSTALL_SWIFTPM}" ]] ; then From cd4018e80cbbb5a22f83b3977e887bbfc26695c9 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Mon, 22 Jul 2019 15:55:33 -0700 Subject: [PATCH 014/115] Dump PrettyStackTrace on Ctrl-T in a frontend job (#26234) It'll dump it for all the frontend jobs spawned from a driver, too, but then the driver will buffer the response, so it's not that useful. Requires LLVM r365911. --- lib/FrontendTool/FrontendTool.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index eb6ade25e353b..ee55d51145934 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -1607,6 +1607,7 @@ int swift::performFrontend(ArrayRef Args, const char *Argv0, void *MainAddr, FrontendObserver *observer) { INITIALIZE_LLVM(); + llvm::EnablePrettyStackTraceOnSigInfoForThisThread(); PrintingDiagnosticConsumer PDC; From cf2de662cd78306033e9dd9c7b256058f45b2e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferrie=CC=80re?= Date: Mon, 22 Jul 2019 15:55:25 -0700 Subject: [PATCH 015/115] ClangImporter: update test where the keyword order changed rdar://problem/53281050 --- test/ClangImporter/CoreGraphics_test.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/ClangImporter/CoreGraphics_test.swift b/test/ClangImporter/CoreGraphics_test.swift index dad3bd50cc8d8..017265f52a220 100644 --- a/test/ClangImporter/CoreGraphics_test.swift +++ b/test/ClangImporter/CoreGraphics_test.swift @@ -115,8 +115,8 @@ public func testRenames(transform: CGAffineTransform, context: CGContext, context.clip(to: rect) context.clip(to: rect, mask: image) -// CHECK: call void @CGContextClipToRect(%struct.CGContext* [[CONTEXT]], %struct.CGRect* byval nonnull align 8 %{{.*}}) -// CHECK: call void @CGContextClipToMask(%struct.CGContext* [[CONTEXT]], %struct.CGRect* byval nonnull align 8 %{{.*}}, %struct.CGImage* %{{.*}}) +// CHECK: call void @CGContextClipToRect(%struct.CGContext* [[CONTEXT]], %struct.CGRect* nonnull byval align 8 %{{.*}}) +// CHECK: call void @CGContextClipToMask(%struct.CGContext* [[CONTEXT]], %struct.CGRect* nonnull byval align 8 %{{.*}}, %struct.CGImage* %{{.*}}) var slice = CGRect.zero var remainder = CGRect.zero @@ -124,7 +124,7 @@ public func testRenames(transform: CGAffineTransform, context: CGContext, from: edge) assert((slice, remainder) == rect.divided(atDistance: CGFloat(2.0), from: edge)) -// CHECK: call void @CGRectDivide(%struct.CGRect* byval nonnull align 8 %{{.*}}, %struct.CGRect* nonnull %{{.*}}, %struct.CGRect* nonnull %{{.*}}, double {{2\.0+.*}}, i32 %{{.*}}) +// CHECK: call void @CGRectDivide(%struct.CGRect* nonnull byval align 8 %{{.*}}, %struct.CGRect* nonnull %{{.*}}, %struct.CGRect* nonnull %{{.*}}, double {{2\.0+.*}}, i32 %{{.*}}) // // CHECK: ret void } From 0f3f54cc553f41e65cdffb67fcda0f138eddd708 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 24 Jul 2019 18:43:55 -0700 Subject: [PATCH 016/115] [build-script] Pass Swift_DIR to standalone LLDB build Upstream we changed the LLDB standalone build to use LLVM_DIR and Clang_DIR to find LLVM and Clang respectively. This commit does the same for Swift, making everything use Swift_DIR instead of our hand-rolled variables. --- utils/build-script-impl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/utils/build-script-impl b/utils/build-script-impl index 09d705f9a2b01..9cc814e91ce5e 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -2471,11 +2471,10 @@ for host in "${ALL_HOSTS[@]}"; do -DLLDB_SWIFTC:PATH="$(build_directory ${LOCAL_HOST} swift)/bin/swiftc" -DLLDB_SWIFT_LIBS:PATH="$(build_directory ${LOCAL_HOST} swift)/lib/swift" -DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})" - -DClang_DIR:PATH=${llvm_build_dir}/lib/cmake/clang -DLLVM_DIR:PATH=${llvm_build_dir}/lib/cmake/llvm - -DLLDB_PATH_TO_CLANG_BUILD:PATH="${llvm_build_dir}" + -DClang_DIR:PATH=${llvm_build_dir}/lib/cmake/clang + -DSwift_DIR:PATH=${swift_build_dir}/lib/cmake/swift -DLLDB_PATH_TO_SWIFT_SOURCE:PATH="${SWIFT_SOURCE_DIR}" - -DLLDB_PATH_TO_SWIFT_BUILD:PATH="${swift_build_dir}" -DLLDB_IS_BUILDBOT_BUILD:BOOL="${LLDB_IS_BUILDBOT_BUILD}" -DLLDB_BUILD_DATE:STRING="\"${LLDB_BUILD_DATE}\"" -DLLDB_ALLOW_STATIC_BINDINGS:BOOL=1 From a66344b7dde7368d1a8f811f5a6fdcde58c9efe1 Mon Sep 17 00:00:00 2001 From: Ben Cohen Date: Fri, 26 Jul 2019 11:57:57 -0700 Subject: [PATCH 017/115] Fix a couple of IRGen tests on master-next (#26358) * objc symbols changed from private to internal * Update LLVM label syntax --- test/IRGen/objc_globals.swift | 4 ++-- test/IRGen/unmanaged_objc_throw_func.swift | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/IRGen/objc_globals.swift b/test/IRGen/objc_globals.swift index c4022d143a029..27a22bf0f18f0 100644 --- a/test/IRGen/objc_globals.swift +++ b/test/IRGen/objc_globals.swift @@ -11,8 +11,8 @@ func blackHole(_ t: T) { } // CHECK-DAG: @"OBJC_CLASS_$_NSNumber" = external global %struct._class_t // CHECK-DAG: @"OBJC_CLASS_$_NSString" = external global %struct._class_t -// CHECK-DAG: @"OBJC_CLASSLIST_REFERENCES_$_{{.*}}" = private global %struct._class_t* @"OBJC_CLASS_$_NSNumber", section "__DATA,__objc_classrefs,regular,no_dead_strip" -// CHECK-DAG: @"OBJC_CLASSLIST_REFERENCES_$_{{.*}}" = private global %struct._class_t* @"OBJC_CLASS_$_NSString", section "__DATA,__objc_classrefs,regular,no_dead_strip" +// CHECK-DAG: @"OBJC_CLASSLIST_REFERENCES_$_{{.*}}" = internal global %struct._class_t* @"OBJC_CLASS_$_NSNumber", section "__DATA,__objc_classrefs,regular,no_dead_strip" +// CHECK-DAG: @"OBJC_CLASSLIST_REFERENCES_$_{{.*}}" = internal global %struct._class_t* @"OBJC_CLASS_$_NSString", section "__DATA,__objc_classrefs,regular,no_dead_strip" public func testLiterals() { blackHole(gadget.giveMeASelector()) diff --git a/test/IRGen/unmanaged_objc_throw_func.swift b/test/IRGen/unmanaged_objc_throw_func.swift index 280703c123fec..dcccf5174ba71 100644 --- a/test/IRGen/unmanaged_objc_throw_func.swift +++ b/test/IRGen/unmanaged_objc_throw_func.swift @@ -33,22 +33,22 @@ import Foundation // CHECK-NEXT: %[[T3:.+]] = icmp ne %swift.error* %[[T2]], null // CHECK-NEXT: br i1 %[[T3]], label %[[L1:.+]], label %[[L2:.+]] -// CHECK: ;