From 7a5ef4bdd10560e9e4fe3f53fee0b506f90de102 Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Mon, 28 Nov 2016 16:55:15 +0000 Subject: [PATCH] Support building swift/AST with MSVC on Windows --- include/swift/AST/AnyFunctionRef.h | 10 +++++++++- include/swift/AST/Decl.h | 4 ++++ include/swift/AST/Expr.h | 16 ++++++++++++++++ include/swift/AST/GenericEnvironment.h | 2 ++ include/swift/AST/Module.h | 12 +++++++++++- include/swift/AST/ProtocolConformance.h | 4 ++++ include/swift/AST/TypeMatcher.h | 2 ++ include/swift/AST/TypeRepr.h | 3 +++ include/swift/AST/Types.h | 16 +++++++++++++++- lib/AST/ASTContext.cpp | 14 ++++++++++++++ lib/AST/ASTMangler.cpp | 10 ++++++---- lib/AST/ASTPrinter.cpp | 4 +++- lib/AST/ASTScope.cpp | 18 ++++++++++++++++++ lib/AST/ASTVerifier.cpp | 2 ++ lib/AST/Attr.cpp | 4 ++++ lib/AST/Builtins.cpp | 2 ++ lib/AST/ConformanceLookupTable.cpp | 4 ++++ lib/AST/ConformanceLookupTable.h | 4 ++++ lib/AST/Decl.cpp | 8 ++++++++ lib/AST/DeclContext.cpp | 14 ++++++++++++++ lib/AST/DefaultArgumentKind.cpp | 2 ++ lib/AST/DiagnosticEngine.cpp | 4 ++++ lib/AST/Expr.cpp | 4 ++++ lib/AST/ForeignRepresentationInfo.h | 4 ++++ lib/AST/Mangle.cpp | 2 +- lib/AST/Module.cpp | 3 +++ lib/AST/NameLookup.cpp | 4 ++++ lib/AST/ProtocolConformance.cpp | 4 ++++ lib/AST/Stmt.cpp | 6 ++++++ lib/AST/Type.cpp | 6 ++++++ lib/AST/TypeRefinementContext.cpp | 4 ++++ lib/Markup/AST.cpp | 4 ++++ 32 files changed, 191 insertions(+), 9 deletions(-) diff --git a/include/swift/AST/AnyFunctionRef.h b/include/swift/AST/AnyFunctionRef.h index 5e550204a16b5..56148baccde07 100644 --- a/include/swift/AST/AnyFunctionRef.h +++ b/include/swift/AST/AnyFunctionRef.h @@ -149,7 +149,12 @@ class AnyFunctionRef { } llvm_unreachable("unexpected AnyFunctionRef representation"); } - + +// Disable "only for use within the debugger" warning. +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable: 4996) +#endif LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED, "only for use within the debugger") { if (auto afd = TheFunction.dyn_cast()) { @@ -171,6 +176,9 @@ class AnyFunctionRef { llvm_unreachable("unexpected AnyFunctionRef representation"); } }; +#if defined(_MSC_VER) +#pragma warning(pop) +#endif } // namespace swift diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 22fcbdda0c441..7f73edbe3a3d9 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -863,7 +863,11 @@ class alignas(1 << DeclAlignInBits) Decl { // Make vanilla new/delete illegal for Decls. void *operator new(size_t Bytes) = delete; + + // Work around MSVC error: attempting to reference a deleted function. +#if !defined(_MSC_VER) || defined(__clang__) void operator delete(void *Data) = delete; +#endif // Only allow allocation of Decls using the allocator in ASTContext // or by doing a placement new. diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h index eafe5647b7f94..112e9246e1c49 100644 --- a/include/swift/AST/Expr.h +++ b/include/swift/AST/Expr.h @@ -662,13 +662,27 @@ class TrailingCallArguments return *static_cast(this); } + // Work around MSVC bug: can't infer llvm::trailing_objects_internal, + // even though we granted friend access to it. size_t numTrailingObjects( +#if defined(_MSC_VER) && !defined(__clang__) + llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken< + Identifier>) const { +#else typename TrailingObjects::template OverloadToken) const { +#endif return asDerived().getNumArguments(); } + // Work around MSVC bug: can't infer llvm::trailing_objects_internal, + // even though we granted friend access to it. size_t numTrailingObjects( +#if defined(_MSC_VER) && !defined(__clang__) + llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken< + SourceLoc>) const { +#else typename TrailingObjects::template OverloadToken) const { +#endif return asDerived().hasArgumentLabelLocs() ? asDerived().getNumArguments() : 0; @@ -4447,6 +4461,8 @@ class ObjCSelectorExpr : public Expr { case ObjCSelectorKind::Setter: return true; } + + llvm_unreachable("Unhandled ObjcSelectorKind in switch."); } /// Whether this selector references a method. diff --git a/include/swift/AST/GenericEnvironment.h b/include/swift/AST/GenericEnvironment.h index a7fd09dfbd8e3..0371a3b016391 100644 --- a/include/swift/AST/GenericEnvironment.h +++ b/include/swift/AST/GenericEnvironment.h @@ -183,7 +183,9 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final /// Make vanilla new/delete illegal. void *operator new(size_t Bytes) = delete; +#if !defined(_MSC_VER) || defined(__clang__) void operator delete(void *Data) = delete; +#endif /// Only allow placement new. void *operator new(size_t Bytes, void *Mem) { diff --git a/include/swift/AST/Module.h b/include/swift/AST/Module.h index 503a1103e73d8..0eda3f78d705f 100644 --- a/include/swift/AST/Module.h +++ b/include/swift/AST/Module.h @@ -506,7 +506,11 @@ class ModuleDecl : public TypeDecl, public DeclContext { private: // Make placement new and vanilla new/delete illegal for Modules. void *operator new(size_t Bytes) throw() = delete; + + // Work around MSVC error: attempting to reference a deleted function. +#if !defined(_MSC_VER) && !defined(__clang__) void operator delete(void *Data) throw() = delete; +#endif void *operator new(size_t Bytes, void *Mem) throw() = delete; public: // Only allow allocation of Modules using the allocator in ASTContext @@ -515,6 +519,8 @@ class ModuleDecl : public TypeDecl, public DeclContext { unsigned Alignment = alignof(ModuleDecl)); }; +static inline unsigned alignOfFileUnit(); + /// A container for module-scope declarations that itself provides a scope; the /// smallest unit of code organization. /// @@ -741,8 +747,12 @@ class FileUnit : public DeclContext { // Only allow allocation of FileUnits using the allocator in ASTContext // or by doing a placement new. void *operator new(size_t Bytes, ASTContext &C, - unsigned Alignment = alignof(FileUnit)); + unsigned Alignment = alignOfFileUnit()); }; + +static inline unsigned alignOfFileUnit() { + return alignof(FileUnit&); +} /// A file containing Swift source code. /// diff --git a/include/swift/AST/ProtocolConformance.h b/include/swift/AST/ProtocolConformance.h index 5adb23c955188..6981f6d8f5698 100644 --- a/include/swift/AST/ProtocolConformance.h +++ b/include/swift/AST/ProtocolConformance.h @@ -265,7 +265,11 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance { // Make vanilla new/delete illegal for protocol conformances. void *operator new(size_t bytes) = delete; + + // Work around MSVC error: attempting to reference a deleted function. +#if !defined(_MSC_VER) || defined(__clang__) void operator delete(void *data) = delete; +#endif // Only allow allocation of protocol conformances using the allocator in // ASTContext or by doing a placement new. diff --git a/include/swift/AST/TypeMatcher.h b/include/swift/AST/TypeMatcher.h index 528dd4de1daba..5899d5ba4db6c 100644 --- a/include/swift/AST/TypeMatcher.h +++ b/include/swift/AST/TypeMatcher.h @@ -69,6 +69,8 @@ class TypeMatcher { cast(secondType.getPointer())); #include "swift/AST/TypeNodes.def" } + + llvm_unreachable("Unhandled TypeKind in switch."); } /// Honeypot to catch cases where we should redispatch the second type, but diff --git a/include/swift/AST/TypeRepr.h b/include/swift/AST/TypeRepr.h index c74ee03f2c6e6..73811bfedc8af 100644 --- a/include/swift/AST/TypeRepr.h +++ b/include/swift/AST/TypeRepr.h @@ -42,7 +42,10 @@ enum class TypeReprKind : uint8_t { /// \brief Representation of a type as written in source. class alignas(8) TypeRepr { + // Fix MSVC error: attempting to reference a deleted function. +#if !defined(_MSC_VER) || defined(__clang__) TypeRepr(const TypeRepr&) = delete; +#endif void operator=(const TypeRepr&) = delete; class TypeReprBitfields { diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index 3f46782d39c94..a3c4709e6ea27 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -1381,7 +1381,7 @@ class ParameterTypeFlags { NumBits = 3 }; OptionSet value; - static_assert(NumBits < 8*sizeof(value), "overflowed"); + static_assert(NumBits < 8*sizeof(OptionSet), "overflowed"); ParameterTypeFlags(OptionSet val) : value(val) {} @@ -2255,6 +2255,8 @@ inline bool canBeCalledIndirectly(SILFunctionTypeRepresentation rep) { case SILFunctionTypeRepresentation::WitnessMethod: return true; } + + llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch."); } /// Map a SIL function representation to the base language calling convention @@ -2273,6 +2275,8 @@ getSILFunctionLanguage(SILFunctionTypeRepresentation rep) { case SILFunctionTypeRepresentation::Closure: return SILFunctionLanguage::Swift; } + + llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch."); } /// AnyFunctionType - A function type has a single input and result, but @@ -2357,6 +2361,8 @@ class AnyFunctionType : public TypeBase { case SILFunctionTypeRepresentation::WitnessMethod: return true; } + + llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch."); } /// True if the function representation carries context. @@ -2373,6 +2379,8 @@ class AnyFunctionType : public TypeBase { case SILFunctionTypeRepresentation::Closure: return false; } + + llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch."); } // Note that we don't have setters. That is by design, use @@ -3043,6 +3051,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode, case Representation::WitnessMethod: return true; } + + llvm_unreachable("Unhandled Representation in switch."); } bool hasGuaranteedSelfParam() const { @@ -3058,6 +3068,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode, case Representation::WitnessMethod: return true; } + + llvm_unreachable("Unhandled Representation in switch."); } /// True if the function representation carries context. @@ -3074,6 +3086,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode, case Representation::Closure: return false; } + + llvm_unreachable("Unhandled Representation in switch."); } // Note that we don't have setters. That is by design, use diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index ce69bef92465c..420a29f0997b3 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -275,8 +275,16 @@ struct ASTContext::Implementation { ~Arena() { for (auto &conformance : SpecializedConformances) conformance.~SpecializedProtocolConformance(); + // Work around MSVC warning: local variable is initialized but + // not referenced. +#if defined(_MSC_VER) +#pragma warning (disable: 4189) +#endif for (auto &conformance : InheritedConformances) conformance.~InheritedProtocolConformance(); +#if defined(_MSC_VER) +#pragma warning (default: 4189) +#endif // Call the normal conformance destructors last since they could be // referenced by the other conformance types. @@ -536,6 +544,8 @@ EnumDecl *ASTContext::getOptionalDecl(OptionalTypeKind kind) const { case OTK_Optional: return getOptionalDecl(); } + + llvm_unreachable("Unhandled OptionalTypeKind in switch."); } static EnumElementDecl *findEnumElement(EnumDecl *e, Identifier name) { @@ -1714,6 +1724,8 @@ std::pair swift::getObjCMethodDiagInfo( // Normal method. return { 4, func->getFullName() }; } + + llvm_unreachable("Unhandled AccessorKind in switch."); } bool swift::fixDeclarationName(InFlightDiagnostic &diag, ValueDecl *decl, @@ -3760,6 +3772,8 @@ ASTContext::getForeignRepresentationInfo(NominalTypeDecl *nominal, case ForeignLanguage::ObjectiveC: return entry; } + + llvm_unreachable("Unhandled ForeignLanguage in switch."); } bool ASTContext::isTypeBridgedInExternalModule( diff --git a/lib/AST/ASTMangler.cpp b/lib/AST/ASTMangler.cpp index c454ffdc23e8b..aecf5d41f281b 100644 --- a/lib/AST/ASTMangler.cpp +++ b/lib/AST/ASTMangler.cpp @@ -36,11 +36,11 @@ #include "llvm/Support/CommandLine.h" using namespace swift; -using namespace NewMangling; +using namespace swift::NewMangling; std::string NewMangling::mangleTypeForDebugger(Type Ty, const DeclContext *DC) { if (useNewMangling()) { - ASTMangler::ASTMangler NewMangler(/* DWARF */ true); + ASTMangler NewMangler(/* DWARF */ true); return NewMangler.mangleTypeForDebugger(Ty, DC); } Mangle::Mangler OldMangler(/* DWARF */ true); @@ -50,7 +50,7 @@ std::string NewMangling::mangleTypeForDebugger(Type Ty, const DeclContext *DC) { std::string NewMangling::mangleTypeAsUSR(Type Ty) { if (useNewMangling()) { - ASTMangler::ASTMangler NewMangler; + ASTMangler NewMangler; return NewMangler.mangleTypeAsUSR(Ty); } Mangle::Mangler OldMangler; @@ -369,7 +369,7 @@ void ASTMangler::appendDeclName(const ValueDecl *decl) { assert(!discriminator.empty()); assert(!isNonAscii(discriminator.str()) && "discriminator contains non-ASCII characters"); - (void)isNonAscii; + (void)&isNonAscii; assert(!clang::isDigit(discriminator.str().front()) && "not a valid identifier"); @@ -387,6 +387,8 @@ static const char *getMetatypeRepresentationOp(MetatypeRepresentation Rep) { case MetatypeRepresentation::ObjC: return "o"; } + + llvm_unreachable("Unhandled MetatypeRepresentation in switch."); } static bool isStdlibType(const NominalTypeDecl *decl) { diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index a14bbaef7c824..57b950519646a 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -477,7 +477,7 @@ std::string ASTPrinter::sanitizeUtf8(StringRef Text) { Builder.reserve(Text.size()); const UTF8* Data = reinterpret_cast(Text.begin()); const UTF8* End = reinterpret_cast(Text.end()); - StringRef Replacement = "\ufffd"; + StringRef Replacement = u8"\ufffd"; while (Data < End) { auto Step = getNumBytesForUTF8(*Data); if (Data + Step > End) { @@ -612,6 +612,8 @@ static bool escapeKeywordInContext(StringRef keyword, PrintNameContext context){ case PrintNameContext::TupleElement: return !canBeArgumentLabel(keyword); } + + llvm_unreachable("Unhandled PrintNameContext in switch."); } void ASTPrinter::printName(Identifier Name, PrintNameContext Context) { diff --git a/lib/AST/ASTScope.cpp b/lib/AST/ASTScope.cpp index add1df1b09e14..a347c15209d85 100644 --- a/lib/AST/ASTScope.cpp +++ b/lib/AST/ASTScope.cpp @@ -37,6 +37,8 @@ const ASTScope *ASTScope::getActiveContinuation() const { case ContinuationKind::ActiveThenSourceFile: return continuation.getPointer(); } + + llvm_unreachable("Unhandled ContinuationKind in switch."); } const ASTScope *ASTScope::getHistoricalContinuation() const { @@ -48,6 +50,8 @@ const ASTScope *ASTScope::getHistoricalContinuation() const { case ContinuationKind::ActiveThenSourceFile: return getSourceFileScope(); } + + llvm_unreachable("Unhandled ContinuationKind in switch."); } void ASTScope::addActiveContinuation(const ASTScope *newContinuation) const { @@ -177,6 +181,8 @@ static bool hasAccessors(AbstractStorageDecl *asd) { case AbstractStorageDecl::StoredWithTrivialAccessors: return false; } + + llvm_unreachable("Unhandled ContinuationKind in switch."); } /// Determine whether this is a top-level code declaration that isn't just @@ -1074,6 +1080,8 @@ ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Decl *decl) { return nullptr; } } + + llvm_unreachable("Unhandled DeclKind in switch."); } ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Stmt *stmt) { @@ -1147,6 +1155,8 @@ ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Stmt *stmt) { // Nothing to do for these statements. return nullptr; } + + llvm_unreachable("Unhandled StmtKind in switch."); } /// Find all of the (non-nested) closures referenced within this expression. @@ -1272,6 +1282,8 @@ bool ASTScope::canStealContinuation() const { // Guard conditions steal continuations. return conditionalClause.isGuardContinuation; } + + llvm_unreachable("Unhandled ASTScopeKind in switch."); } void ASTScope::enumerateContinuationScopes( @@ -1381,6 +1393,8 @@ ASTContext &ASTScope::getASTContext() const { case ASTScopeKind::TopLevelCode: return static_cast(topLevelCode)->getASTContext(); } + + llvm_unreachable("Unhandled ASTScopeKind in switch."); } const ASTScope *ASTScope::getSourceFileScope() const { @@ -1659,6 +1673,8 @@ SourceRange ASTScope::getSourceRangeImpl() const { case ASTScopeKind::TopLevelCode: return topLevelCode->getSourceRange(); } + + llvm_unreachable("Unhandled ASTScopeKind in switch."); } /// Find the innermost enclosing scope that contains this source location. @@ -1769,6 +1785,8 @@ DeclContext *ASTScope::getDeclContext() const { case ASTScopeKind::AbstractFunctionBody: return nullptr; } + + llvm_unreachable("Unhandled ASTScopeKind in switch."); } DeclContext *ASTScope::getInnermostEnclosingDeclContext() const { diff --git a/lib/AST/ASTVerifier.cpp b/lib/AST/ASTVerifier.cpp index 7a9a901f4d526..3abc0ba4d542e 100644 --- a/lib/AST/ASTVerifier.cpp +++ b/lib/AST/ASTVerifier.cpp @@ -1709,6 +1709,8 @@ struct ASTNodeBase {}; case DeclContextKind::SubscriptDecl: return hasEnclosingFunctionContext(dc->getParent()); } + + llvm_unreachable("Unhandled DeclContextKind in switch."); } void verifyChecked(ValueDecl *VD) { diff --git a/lib/AST/Attr.cpp b/lib/AST/Attr.cpp index 99c86919496a7..a2e0bb4aaec6a 100644 --- a/lib/AST/Attr.cpp +++ b/lib/AST/Attr.cpp @@ -710,6 +710,8 @@ bool AvailableAttr::isUnconditionallyUnavailable() const { case PlatformAgnosticAvailabilityKind::UnavailableInSwift: return true; } + + llvm_unreachable("Unhandled PlatformAgnosticAvailabilityKind in switch."); } bool AvailableAttr::isUnconditionallyDeprecated() const { @@ -723,6 +725,8 @@ bool AvailableAttr::isUnconditionallyDeprecated() const { case PlatformAgnosticAvailabilityKind::Deprecated: return true; } + + llvm_unreachable("Unhandled PlatformAgnosticAvailabilityKind in switch."); } AvailableVersionComparison AvailableAttr::getVersionAvailability( diff --git a/lib/AST/Builtins.cpp b/lib/AST/Builtins.cpp index 996c580801d6a..f3434fb78aa64 100644 --- a/lib/AST/Builtins.cpp +++ b/lib/AST/Builtins.cpp @@ -1316,6 +1316,8 @@ static bool isUnknownOrUnordered(llvm::AtomicOrdering ordering) { case AtomicOrdering::SequentiallyConsistent: return false; } + + llvm_unreachable("Unhandled AtomicOrdering in switch."); } static bool isValidCmpXChgOrdering(StringRef SuccessString, diff --git a/lib/AST/ConformanceLookupTable.cpp b/lib/AST/ConformanceLookupTable.cpp index 9b6c1e40319bd..fdf0b67c6b36d 100644 --- a/lib/AST/ConformanceLookupTable.cpp +++ b/lib/AST/ConformanceLookupTable.cpp @@ -36,6 +36,8 @@ DeclContext *ConformanceLookupTable::ConformanceSource::getDeclContext() const { case ConformanceEntryKind::Synthesized: return getSynthesizedDecl(); } + + llvm_unreachable("Unhandled ConformanceEntryKind in switch."); } ProtocolDecl *ConformanceLookupTable::ConformanceEntry::getProtocol() const { @@ -551,6 +553,8 @@ static bool isReplaceable(ConformanceEntryKind kind) { case ConformanceEntryKind::Inherited: return false; } + + llvm_unreachable("Unhandled ConformanceEntryKind in switch."); } ConformanceLookupTable::Ordering ConformanceLookupTable::compareConformances( diff --git a/lib/AST/ConformanceLookupTable.h b/lib/AST/ConformanceLookupTable.h index 115d4a8ccb342..e9a8bb2190b5a 100644 --- a/lib/AST/ConformanceLookupTable.h +++ b/lib/AST/ConformanceLookupTable.h @@ -152,6 +152,8 @@ class ConformanceLookupTable { ? ConformanceEntryKind::Synthesized : ConformanceEntryKind::Implied; } + + llvm_unreachable("Unhandled ConformanceEntryKind in switch."); } /// For an inherited conformance, retrieve the class declaration @@ -229,6 +231,8 @@ class ConformanceLookupTable { case ConformanceEntryKind::Inherited: return true; } + + llvm_unreachable("Unhandled ConformanceEntryKind in switch."); } /// Whether this protocol conformance was superseded by another diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 7e6adb735c0a5..60b12f1b4ccf4 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1255,6 +1255,8 @@ bool AbstractStorageDecl::hasFixedLayout() const { case ResilienceStrategy::Default: return true; } + + llvm_unreachable("Unhandled ResilienceStrategy in switch."); } bool AbstractStorageDecl::hasFixedLayout(ModuleDecl *M, @@ -1962,6 +1964,8 @@ bool NominalTypeDecl::hasFixedLayout() const { case ResilienceStrategy::Default: return true; } + + llvm_unreachable("Unhandled ResilienceStrategy in switch."); } bool NominalTypeDecl::hasFixedLayout(ModuleDecl *M, @@ -2086,6 +2090,8 @@ static Type computeNominalType(NominalTypeDecl *decl, DeclTypeKind kind) { return BoundGenericType::get(decl, Ty, args); } } + + llvm_unreachable("Unhandled DeclTypeKind in switch."); } else { return NominalType::get(decl, Ty, ctx); } @@ -3035,6 +3041,8 @@ bool AbstractStorageDecl::isGetterMutating() const { assert(getAddressor()); return getAddressor()->isMutating(); } + + llvm_unreachable("Unhandled AbstractStorageDecl in switch."); } /// \brief Return true if the 'setter' is nonmutating, i.e. that it can be diff --git a/lib/AST/DeclContext.cpp b/lib/AST/DeclContext.cpp index fc20d934a7b70..555ab89f8892c 100644 --- a/lib/AST/DeclContext.cpp +++ b/lib/AST/DeclContext.cpp @@ -73,6 +73,8 @@ DeclContext::getAsTypeOrTypeExtensionContext() const { case DeclContextKind::GenericTypeDecl: return const_cast(cast(this)); } + + llvm_unreachable("Unhandled DeclContextKind in switch."); } /// If this DeclContext is a NominalType declaration or an @@ -152,6 +154,8 @@ static Type computeExtensionType(const ExtensionDecl *ED, DeclTypeKind kind) { // FIXME: Need a sugar-preserving getExtendedInterfaceType for extensions return type->getAnyNominal()->getDeclaredInterfaceType(); } + + llvm_unreachable("Unhandled DeclTypeKind in switch."); } Type DeclContext::getDeclaredTypeOfContext() const { @@ -634,6 +638,8 @@ bool DeclContext::classof(const Decl *D) { #define CONTEXT_VALUE_DECL(ID, PARENT) case DeclKind::ID: return true; #include "swift/AST/DeclNodes.def" } + + llvm_unreachable("Unhandled DeclKind in switch."); } DeclContext *DeclContext::castDeclToDeclContext(const Decl *D) { @@ -647,6 +653,8 @@ DeclContext *DeclContext::castDeclToDeclContext(const Decl *D) { #define CONTEXT_VALUE_DECL(ID, PARENT) CONTEXT_DECL(ID, PARENT) #include "swift/AST/DeclNodes.def" } + + llvm_unreachable("Unhandled DeclKind in switch."); } unsigned DeclContext::printContext(raw_ostream &OS, unsigned indent) const { @@ -786,6 +794,8 @@ ASTContext &IterableDeclContext::getASTContext() const { case IterableDeclContextKind::ExtensionDecl: return cast(this)->getASTContext(); } + + llvm_unreachable("Unhandled IterableDeclContextKind in switch."); } DeclRange IterableDeclContext::getMembers() const { @@ -891,6 +901,8 @@ bool IterableDeclContext::classof(const Decl *D) { #define EXTENSION_DECL(ID, PARENT) case DeclKind::ID: return true; #include "swift/AST/DeclNodes.def" } + + llvm_unreachable("Unhandled DeclKind in switch."); } IterableDeclContext * @@ -908,6 +920,8 @@ IterableDeclContext::castDeclToIterableDeclContext(const Decl *D) { static_cast(cast(D))); #include "swift/AST/DeclNodes.def" } + + llvm_unreachable("Unhandled DeclKind in switch."); } AccessScope::AccessScope(const DeclContext *DC, bool isPrivate) diff --git a/lib/AST/DefaultArgumentKind.cpp b/lib/AST/DefaultArgumentKind.cpp index 7471ac412a81e..1952a39e19e04 100644 --- a/lib/AST/DefaultArgumentKind.cpp +++ b/lib/AST/DefaultArgumentKind.cpp @@ -34,6 +34,8 @@ StringRef swift::getDefaultArgumentSpelling(DefaultArgumentKind kind) { case DefaultArgumentKind::EmptyArray: return "[]"; case DefaultArgumentKind::EmptyDictionary: return "[:]"; } + + llvm_unreachable("Unhandled DefaultArgumentKind in switch."); } DefaultArgumentKind swift::inferDefaultArgumentKind(Expr *expr) { diff --git a/lib/AST/DiagnosticEngine.cpp b/lib/AST/DiagnosticEngine.cpp index ad5d742d43889..01e619b65bc7a 100644 --- a/lib/AST/DiagnosticEngine.cpp +++ b/lib/AST/DiagnosticEngine.cpp @@ -523,6 +523,8 @@ static DiagnosticKind toDiagnosticKind(DiagnosticState::Behavior behavior) { case DiagnosticState::Behavior::Warning: return DiagnosticKind::Warning; } + + llvm_unreachable("Unhandled DiagnosticKind in switch."); } DiagnosticState::Behavior DiagnosticState::determineBehavior(DiagID id) { @@ -584,6 +586,8 @@ DiagnosticState::Behavior DiagnosticState::determineBehavior(DiagID id) { case DiagnosticKind::Warning: return set(Behavior::Warning); } + + llvm_unreachable("Unhandled DiagnosticKind in switch."); } void DiagnosticEngine::flushActiveDiagnostic() { diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index ab3a2fb55345e..c99e41092e9ef 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -41,6 +41,8 @@ StringRef swift::getFunctionRefKindStr(FunctionRefKind refKind) { case FunctionRefKind::Compound: return "compound"; } + + llvm_unreachable("Unhandled FunctionRefKind in switch."); } //===----------------------------------------------------------------------===// @@ -777,6 +779,8 @@ bool Expr::canAppendCallParentheses() const { case ExprKind::EditorPlaceholder: return false; } + + llvm_unreachable("Unhandled ExprKind in switch."); } llvm::DenseMap Expr::getParentMap() { diff --git a/lib/AST/ForeignRepresentationInfo.h b/lib/AST/ForeignRepresentationInfo.h index c72aa4202a89b..7dd06292446af 100644 --- a/lib/AST/ForeignRepresentationInfo.h +++ b/lib/AST/ForeignRepresentationInfo.h @@ -107,6 +107,8 @@ class ForeignRepresentationInfo { case ForeignRepresentableKind::StaticBridged: llvm_unreachable("unexpected kind in ForeignRepresentableCacheEntry"); } + + llvm_unreachable("Unhandled ForeignRepresentableKind in switch."); } /// Returns true if the optional version of this type is also representable. @@ -136,6 +138,8 @@ class ForeignRepresentationInfo { case ForeignRepresentableKind::StaticBridged: llvm_unreachable("unexpected kind in ForeignRepresentableCacheEntry"); } + + llvm_unreachable("Unhandled ForeignRepresentableKind in switch."); } }; diff --git a/lib/AST/Mangle.cpp b/lib/AST/Mangle.cpp index 9d3ca2d98d20c..5ea267e302d7b 100644 --- a/lib/AST/Mangle.cpp +++ b/lib/AST/Mangle.cpp @@ -423,7 +423,7 @@ void Mangler::mangleDeclName(const ValueDecl *decl) { assert(!discriminator.empty()); assert(!isNonAscii(discriminator.str()) && "discriminator contains non-ASCII characters"); - (void)isNonAscii; + (void)&isNonAscii; assert(!clang::isDigit(discriminator.str().front()) && "not a valid identifier"); diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index 05551a0db0865..0a5b1421425c0 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -841,7 +841,10 @@ namespace { template struct OperatorLookup { + // This assertion fails in MSVC, but not clang-cl. +#if !defined(_MSC_VER) || defined(__clang__) static_assert(static_cast(nullptr), "Only usable with operators"); +#endif }; template <> diff --git a/lib/AST/NameLookup.cpp b/lib/AST/NameLookup.cpp index 98ccb556a0626..7e89e5e49b0e1 100644 --- a/lib/AST/NameLookup.cpp +++ b/lib/AST/NameLookup.cpp @@ -427,6 +427,8 @@ static DeclVisibilityKind getLocalDeclVisibilityKind(const ASTScope *scope) { case ASTScopeKind::ForStmtInitializer: return DeclVisibilityKind::LocalVariable; } + + llvm_unreachable("Unhandled ASTScopeKind in switch."); } UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC, @@ -1310,8 +1312,10 @@ bool DeclContext::lookupQualified(Type type, return None; default: // FIXME: Use llvm::CountPopulation_64 when that's declared constexpr. +#if defined(__clang__) || defined(__GNUC__) static_assert(__builtin_popcountll(NL_KnownDependencyMask) == 2, "mask should only include four values"); +#endif llvm_unreachable("mask only includes four values"); } }; diff --git a/lib/AST/ProtocolConformance.cpp b/lib/AST/ProtocolConformance.cpp index 5d85846a40cf1..a2fd35f119247 100644 --- a/lib/AST/ProtocolConformance.cpp +++ b/lib/AST/ProtocolConformance.cpp @@ -221,6 +221,8 @@ GenericEnvironment *ProtocolConformance::getGenericEnvironment() const { // FIXME: We could return a meaningful GenericEnvironment here return nullptr; } + + llvm_unreachable("Unhandled ProtocolConformanceKind in switch."); } GenericSignature *ProtocolConformance::getGenericSignature() const { @@ -237,6 +239,8 @@ GenericSignature *ProtocolConformance::getGenericSignature() const { // type variables. return nullptr; } + + llvm_unreachable("Unhandled ProtocolConformanceKind in switch."); } bool ProtocolConformance::isBehaviorConformance() const { diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 07cbb1210e5a6..2b7d11f5a8e15 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -317,6 +317,8 @@ SourceRange StmtConditionElement::getSourceRange() const { return SourceRange(); } } + + llvm_unreachable("Unhandled StmtConditionElement in switch."); } SourceLoc StmtConditionElement::getStartLoc() const { @@ -328,6 +330,8 @@ SourceLoc StmtConditionElement::getStartLoc() const { case StmtConditionElement::CK_PatternBinding: return getSourceRange().Start; } + + llvm_unreachable("Unhandled StmtConditionElement in switch."); } SourceLoc StmtConditionElement::getEndLoc() const { @@ -339,6 +343,8 @@ SourceLoc StmtConditionElement::getEndLoc() const { case StmtConditionElement::CK_PatternBinding: return getSourceRange().End; } + + llvm_unreachable("Unhandled StmtConditionElement in switch."); } static StmtCondition exprToCond(Expr *C, ASTContext &Ctx) { diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index ddccb18660597..d04abbac1e392 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -2085,6 +2085,8 @@ getForeignRepresentable(Type type, ForeignLanguage language, anyStaticBridged = true; return false; } + + llvm_unreachable("Unhandled ForeignRepresentableKind in switch."); }; // Check the representation of the function type. @@ -2299,6 +2301,8 @@ bool TypeBase::isRepresentableIn(ForeignLanguage language, case ForeignRepresentableKind::StaticBridged: return true; } + + llvm_unreachable("Unhandled ForeignRepresentableKind in switch."); } bool TypeBase::isTriviallyRepresentableIn(ForeignLanguage language, @@ -2314,6 +2318,8 @@ bool TypeBase::isTriviallyRepresentableIn(ForeignLanguage language, case ForeignRepresentableKind::Object: return true; } + + llvm_unreachable("Unhandled ForeignRepresentableKind in switch."); } /// Is t1 not just a subtype of t2, but one such that its values are diff --git a/lib/AST/TypeRefinementContext.cpp b/lib/AST/TypeRefinementContext.cpp index d1d8dc3714374..61017d337a36a 100644 --- a/lib/AST/TypeRefinementContext.cpp +++ b/lib/AST/TypeRefinementContext.cpp @@ -190,6 +190,8 @@ SourceLoc TypeRefinementContext::getIntroductionLoc() const { case Reason::Root: return SourceLoc(); } + + llvm_unreachable("Unhandled Reason in switch."); } void TypeRefinementContext::print(raw_ostream &OS, SourceManager &SrcMgr, @@ -253,4 +255,6 @@ StringRef TypeRefinementContext::getReasonName(Reason R) { case Reason::WhileStmtBody: return "while_body"; } + + llvm_unreachable("Unhandled Reason in switch."); } diff --git a/lib/Markup/AST.cpp b/lib/Markup/AST.cpp index 98178292dbb41..8ac6b741af04f 100644 --- a/lib/Markup/AST.cpp +++ b/lib/Markup/AST.cpp @@ -241,6 +241,8 @@ ArrayRef MarkupASTNode::getChildren() { #define MARKUP_AST_NODE_RANGE(Id, FirstId, LastId) #include "swift/Markup/ASTNodes.def" } + + llvm_unreachable("Unhandled ASTNodeKind in switch."); } ArrayRef MarkupASTNode::getChildren() const { @@ -252,6 +254,8 @@ return cast(this)->getChildren(); #define MARKUP_AST_NODE_RANGE(Id, FirstId, LastId) #include "swift/Markup/ASTNodes.def" } + + llvm_unreachable("Unhandled ASTNodeKind in switch."); } void swift::markup::printInlinesUnder(const MarkupASTNode *Node,