From 36100bf21cf581c9633aee17e85a5a8a6c62bcd5 Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Thu, 17 Nov 2016 17:42:34 +0000 Subject: [PATCH] Fix errors and warnings building swift/SIL on Windows using MSVC --- include/swift/SIL/Projection.h | 8 ++++++++ include/swift/SIL/SILAllocated.h | 3 +++ include/swift/SIL/SILArgument.h | 4 ++++ include/swift/SIL/SILBasicBlock.h | 4 ++++ include/swift/SIL/SILInstruction.h | 19 +++++++++++++++++++ include/swift/SIL/SILLinkage.h | 8 ++++++++ .../swift/SIL/SILOpenedArchetypesTracker.h | 12 +++++++++++- include/swift/SIL/SILUndef.h | 4 ++++ lib/SIL/AbstractionPattern.cpp | 2 +- lib/SIL/Bridging.cpp | 2 ++ lib/SIL/InstructionUtils.cpp | 2 ++ lib/SIL/Projection.cpp | 6 +++++- lib/SIL/SIL.cpp | 2 ++ lib/SIL/SILFunctionType.cpp | 6 ++++++ lib/SIL/SILInstruction.cpp | 4 ++++ lib/SIL/SILInstructions.cpp | 2 ++ lib/SIL/SILModule.cpp | 4 +++- lib/SIL/SILType.cpp | 5 ++++- lib/SIL/TypeLowering.cpp | 10 ++++++++-- 19 files changed, 100 insertions(+), 7 deletions(-) diff --git a/include/swift/SIL/Projection.h b/include/swift/SIL/Projection.h index 757e61b7bf322..86973a18b3d5b 100644 --- a/include/swift/SIL/Projection.h +++ b/include/swift/SIL/Projection.h @@ -61,6 +61,8 @@ inline bool isStrictSubSeqRelation(SubSeqRelation_t Seq) { case SubSeqRelation_t::RHSStrictSubSeqOfLHS: return true; } + + llvm_unreachable("Unhandled SubSeqRelation_t in switch."); } /// Extract an integer index from a SILValue. @@ -306,6 +308,8 @@ class Projection { // Index types do not change the underlying type. return BaseType; } + + llvm_unreachable("Unhandled ProjectionKind in switch."); } VarDecl *getVarDecl(SILType BaseType) const { @@ -431,6 +435,8 @@ class Projection { case ProjectionKind::Box: return false; } + + llvm_unreachable("Unhandled ProjectionKind in switch."); } bool isNominalKind() const { @@ -448,6 +454,8 @@ class Projection { case ProjectionKind::TailElems: return false; } + + llvm_unreachable("Unhandled ProjectionKind in switch."); } /// Form an aggregate of type BaseType using the SILValue Values. Returns the diff --git a/include/swift/SIL/SILAllocated.h b/include/swift/SIL/SILAllocated.h index 0a5c8474cc27b..624af98525f23 100644 --- a/include/swift/SIL/SILAllocated.h +++ b/include/swift/SIL/SILAllocated.h @@ -28,8 +28,11 @@ class SILAllocated { void *operator new(size_t) = delete; void *operator new[](size_t) = delete; + // Work around MSVC error: attempting to reference a deleted function. +#if !defined(_MSC_VER) || defined(__clang__) /// Disable non-placement delete. void operator delete(void *) = delete; +#endif void operator delete[](void *) = delete; /// Custom version of 'new' that uses the SILModule's BumpPtrAllocator with diff --git a/include/swift/SIL/SILArgument.h b/include/swift/SIL/SILArgument.h index 335ceaf370701..3252a1f8ecab9 100644 --- a/include/swift/SIL/SILArgument.h +++ b/include/swift/SIL/SILArgument.h @@ -36,7 +36,11 @@ SILFunctionType::getSILArgumentConvention(unsigned index) const { class SILArgument : public ValueBase { void operator=(const SILArgument &) = delete; + + // Work around MSVC error: attempting to reference a deleted function. +#if !defined(_MSC_VER) || defined(__clang__) void operator delete(void *Ptr, size_t) = delete; +#endif SILBasicBlock *ParentBB; const ValueDecl *Decl; diff --git a/include/swift/SIL/SILBasicBlock.h b/include/swift/SIL/SILBasicBlock.h index e3e66b3a8a98e..6054314fad8ed 100644 --- a/include/swift/SIL/SILBasicBlock.h +++ b/include/swift/SIL/SILBasicBlock.h @@ -52,7 +52,11 @@ public llvm::ilist_node, public SILAllocated { friend struct llvm::ilist_traits; SILBasicBlock() : Parent(nullptr) {} void operator=(const SILBasicBlock &) = delete; + + // Work around MSVC error: attempting to reference a deleted function. +#if !defined(_MSC_VER) || defined(__clang__) void operator delete(void *Ptr, size_t) = delete; +#endif SILBasicBlock(SILFunction *F, SILBasicBlock *afterBB = nullptr); diff --git a/include/swift/SIL/SILInstruction.h b/include/swift/SIL/SILInstruction.h index 7314fb7654d5c..b11c721ec8f3d 100644 --- a/include/swift/SIL/SILInstruction.h +++ b/include/swift/SIL/SILInstruction.h @@ -80,7 +80,11 @@ class SILInstruction : public ValueBase,public llvm::ilist_node{ SILInstruction() = delete; void operator=(const SILInstruction &) = delete; + + // Work around MSVC error: attempting to reference a deleted function. +#if !defined(_MSC_VER) || defined(__clang__) void operator delete(void *Ptr, size_t) = delete; +#endif /// Check any special state of instructions that are not represented in the /// instructions operands/type. @@ -459,8 +463,15 @@ class UnaryInstructionWithTypeDependentOperandsBase : } } + // 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< + Operand>) const { +#else typename TrailingBase::template OverloadToken) const { +#endif return NumOperands; } @@ -2302,8 +2313,16 @@ class BindMemoryInst final : SILType getBoundType() const { return BoundType ; } // Implement llvm::TrailingObjects. + + // 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< + Operand>) const { +#else typename TrailingBase::template OverloadToken) const { +#endif return NumOperands; } diff --git a/include/swift/SIL/SILLinkage.h b/include/swift/SIL/SILLinkage.h index bc0f93a6e54f5..8372ce0807399 100644 --- a/include/swift/SIL/SILLinkage.h +++ b/include/swift/SIL/SILLinkage.h @@ -13,6 +13,8 @@ #ifndef SWIFT_SIL_SILLINKAGE_H #define SWIFT_SIL_SILLINKAGE_H +#include "llvm/Support/ErrorHandling.h" + namespace swift { /// Linkage for a SIL object. This concept combines the notions @@ -146,6 +148,8 @@ inline bool hasPublicVisibility(SILLinkage linkage) { case SILLinkage::HiddenExternal: return false; } + + llvm_unreachable("Unhandled SILLinkage in switch."); } inline bool hasSharedVisibility(SILLinkage linkage) { @@ -161,6 +165,8 @@ inline bool hasSharedVisibility(SILLinkage linkage) { case SILLinkage::PrivateExternal: return false; } + + llvm_unreachable("Unhandled SILLinkage in switch."); } inline bool hasPrivateVisibility(SILLinkage linkage) { @@ -176,6 +182,8 @@ inline bool hasPrivateVisibility(SILLinkage linkage) { case SILLinkage::SharedExternal: return false; } + + llvm_unreachable("Unhandled SILLinkage in switch."); } /// Returns true if l1 is less visible than l2. diff --git a/include/swift/SIL/SILOpenedArchetypesTracker.h b/include/swift/SIL/SILOpenedArchetypesTracker.h index 856054cfed748..3f455cb3941fe 100644 --- a/include/swift/SIL/SILOpenedArchetypesTracker.h +++ b/include/swift/SIL/SILOpenedArchetypesTracker.h @@ -20,6 +20,12 @@ namespace swift { +// Disable MSVC warning: multiple copy constructors specified. +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable: 4521) +#endif + /// SILOpenedArchetypesTracker is a helper class that can be used to create /// and maintain a mapping from opened archetypes to instructions /// defining them, e.g. open_existential_ref, open_existential_addr, @@ -117,10 +123,10 @@ class SILOpenedArchetypesTracker : public DeleteNotificationHandler { private: // Never copy SILOpenedArchetypesTracker &operator = (const SILOpenedArchetypesTracker &) = delete; - /// The function whose opened archetypes are being tracked. /// Used only for verification purposes. const SILFunction &F; + /// Mapping from opened archetypes to their definitions. OpenedArchetypeDefsMap &OpenedArchetypeDefs; /// Local map to be used if no other map was provided in the @@ -128,6 +134,10 @@ class SILOpenedArchetypesTracker : public DeleteNotificationHandler { OpenedArchetypeDefsMap LocalOpenedArchetypeDefs; }; +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + // A state object containing information about opened archetypes. // This information can be used by constructors of SILInstructions, // their create methods, etc. diff --git a/include/swift/SIL/SILUndef.h b/include/swift/SIL/SILUndef.h index 374e5e410d4f8..f675658a7958d 100644 --- a/include/swift/SIL/SILUndef.h +++ b/include/swift/SIL/SILUndef.h @@ -20,7 +20,11 @@ namespace swift { class SILUndef : public ValueBase { void operator=(const SILArgument &) = delete; + + // Work around MSVC error: attempting to reference a deleted function. +#if !defined(_MSC_VER) || defined(__clang__) void operator delete(void *Ptr, size_t) = delete; +#endif SILUndef(SILType Ty) : ValueBase(ValueKind::SILUndef, Ty) {} public: diff --git a/lib/SIL/AbstractionPattern.cpp b/lib/SIL/AbstractionPattern.cpp index 03cb63dffdd41..eb51a2b7ce903 100644 --- a/lib/SIL/AbstractionPattern.cpp +++ b/lib/SIL/AbstractionPattern.cpp @@ -303,7 +303,7 @@ AbstractionPattern::getTupleElementType(unsigned index) const { if (errorInfo.isErrorParameterReplacedWithVoid()) { if (paramIndex == errorParamIndex) { assert(isVoidLike(swiftEltType)); - (void) isVoidLike; + (void)&isVoidLike; return AbstractionPattern(swiftEltType); } } else { diff --git a/lib/SIL/Bridging.cpp b/lib/SIL/Bridging.cpp index 3193155fa1fca..7135dc58c1490 100644 --- a/lib/SIL/Bridging.cpp +++ b/lib/SIL/Bridging.cpp @@ -132,6 +132,8 @@ Type TypeConverter::getLoweredBridgedType(AbstractionPattern pattern, return getLoweredCBridgedType(pattern, t, canBridgeBool, purpose == ForResult); } + + llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch."); }; Type TypeConverter::getLoweredCBridgedType(AbstractionPattern pattern, diff --git a/lib/SIL/InstructionUtils.cpp b/lib/SIL/InstructionUtils.cpp index 35b0e9fcef8a4..c75df27d5c566 100644 --- a/lib/SIL/InstructionUtils.cpp +++ b/lib/SIL/InstructionUtils.cpp @@ -309,4 +309,6 @@ bool FunctionOwnershipEvaluator::evaluate(SILInstruction *I) { return true; } } + + llvm_unreachable("Unhandled OwnershipQualifiedKind in switch."); } diff --git a/lib/SIL/Projection.cpp b/lib/SIL/Projection.cpp index 5be4f7b7a09bc..fe46b3770748a 100644 --- a/lib/SIL/Projection.cpp +++ b/lib/SIL/Projection.cpp @@ -104,7 +104,7 @@ Projection::Projection(SILInstruction *I) : Value() { } case ValueKind::ProjectBoxInst: { auto *PBI = cast(I); - Value = ValueTy(ProjectionKind::Box, (unsigned)0); + Value = ValueTy(ProjectionKind::Box, static_cast(0)); assert(getKind() == ProjectionKind::Box); assert(getIndex() == 0); assert(getType(PBI->getOperand()->getType(), PBI->getModule()) == @@ -228,6 +228,8 @@ Projection::createObjectProjection(SILBuilder &B, SILLocation Loc, case ProjectionKind::BitwiseCast: return B.createUncheckedBitwiseCast(Loc, Base, getCastType(BaseTy)); } + + llvm_unreachable("Unhandled ProjectionKind in switch."); } NullablePtr @@ -270,6 +272,8 @@ Projection::createAddressProjection(SILBuilder &B, SILLocation Loc, case ProjectionKind::BitwiseCast: return B.createUncheckedAddrCast(Loc, Base, getCastType(BaseTy)); } + + llvm_unreachable("Unhandled ProjectionKind in switch."); } void Projection::getFirstLevelProjections(SILType Ty, SILModule &Mod, diff --git a/lib/SIL/SIL.cpp b/lib/SIL/SIL.cpp index d2c1ea202b111..a8c08d789a01e 100644 --- a/lib/SIL/SIL.cpp +++ b/lib/SIL/SIL.cpp @@ -68,6 +68,8 @@ FormalLinkage swift::getDeclLinkage(const ValueDecl *D) { // access these symbols. return FormalLinkage::HiddenUnique; } + + llvm_unreachable("Unhandled Accessibility in switch."); } FormalLinkage swift::getTypeLinkage(CanType type) { diff --git a/lib/SIL/SILFunctionType.cpp b/lib/SIL/SILFunctionType.cpp index 000b293f69e62..c9c921970cdf7 100644 --- a/lib/SIL/SILFunctionType.cpp +++ b/lib/SIL/SILFunctionType.cpp @@ -1028,6 +1028,8 @@ static CanSILFunctionType getNativeSILFunctionType(SILModule &M, } } } + + llvm_unreachable("Unhandled SILDeclRefKind in switch."); } CanSILFunctionType swift::getNativeSILFunctionType(SILModule &M, @@ -1488,6 +1490,8 @@ static SelectorFamily getSelectorFamily(SILDeclRef c) { case SILDeclRef::Kind::StoredPropertyInitializer: return SelectorFamily::None; } + + llvm_unreachable("Unhandled SILDeclRefKind in switch."); } namespace { @@ -1684,6 +1688,8 @@ TypeConverter::getDeclRefRepresentation(SILDeclRef c) { case SILDeclRef::Kind::IVarDestroyer: return SILFunctionTypeRepresentation::Method; } + + llvm_unreachable("Unhandled SILDeclRefKind in switch."); } SILConstantInfo TypeConverter::getConstantInfo(SILDeclRef constant) { diff --git a/lib/SIL/SILInstruction.cpp b/lib/SIL/SILInstruction.cpp index 91ccf0901735a..d0f359f506104 100644 --- a/lib/SIL/SILInstruction.cpp +++ b/lib/SIL/SILInstruction.cpp @@ -1045,6 +1045,8 @@ llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &OS, case SILInstruction::MemoryBehavior::MayHaveSideEffects: return OS << "MayHaveSideEffects"; } + + llvm_unreachable("Unhandled MemoryBehavior in switch."); } llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &OS, @@ -1055,4 +1057,6 @@ llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &OS, case SILInstruction::ReleasingBehavior::MayRelease: return OS << "MayRelease"; } + + llvm_unreachable("Unhandled ReleasingBehavior in switch."); } diff --git a/lib/SIL/SILInstructions.cpp b/lib/SIL/SILInstructions.cpp index 3d88f287ee201..1c735b891a313 100644 --- a/lib/SIL/SILInstructions.cpp +++ b/lib/SIL/SILInstructions.cpp @@ -976,6 +976,8 @@ bool TermInst::isFunctionExiting() const { case TermKind::ThrowInst: return true; } + + llvm_unreachable("Unhandled TermKind in switch."); } BranchInst::BranchInst(SILDebugLocation Loc, SILBasicBlock *DestBB, diff --git a/lib/SIL/SILModule.cpp b/lib/SIL/SILModule.cpp index a40319463cad2..872d87dcbd579 100644 --- a/lib/SIL/SILModule.cpp +++ b/lib/SIL/SILModule.cpp @@ -279,6 +279,8 @@ static SILFunction::ClassVisibility_t getClassVisibility(SILDeclRef constant) { case Accessibility::Open: return SILFunction::PublicClass; } + + llvm_unreachable("Unhandled Accessibility in switch."); } static bool verifySILSelfParameterType(SILDeclRef DeclRef, @@ -387,7 +389,7 @@ SILFunction *SILModule::getOrCreateFunction(SILLocation loc, // it. CanSILFunctionType FTy = F->getLoweredFunctionType(); if (FTy->hasSelfParam()) { - (void)verifySILSelfParameterType; + (void)&verifySILSelfParameterType; assert(verifySILSelfParameterType(constant, F, FTy) && "Invalid signature for SIL Self parameter type"); } diff --git a/lib/SIL/SILType.cpp b/lib/SIL/SILType.cpp index 2de66f0281ff7..3350baba99905 100644 --- a/lib/SIL/SILType.cpp +++ b/lib/SIL/SILType.cpp @@ -191,7 +191,8 @@ static bool canUnsafeCastEnum(SILType fromType, EnumDecl *fromEnum, } // If toType has more elements, it may be larger. auto fromElements = fromEnum->getAllElements(); - if (numToElements > std::distance(fromElements.begin(), fromElements.end())) + if (static_cast(numToElements) > + std::distance(fromElements.begin(), fromElements.end())) return false; if (toElementTy.isNull()) @@ -549,6 +550,8 @@ SILType::canUseExistentialRepresentation(SILModule &M, case ExistentialRepresentation::Metatype: return is(); } + + llvm_unreachable("Unhandled ExistentialRepresentation in switch."); } SILType SILType::getReferentType(SILModule &M) const { diff --git a/lib/SIL/TypeLowering.cpp b/lib/SIL/TypeLowering.cpp index 3c7379ebc6c50..7aa2b7b18e971 100644 --- a/lib/SIL/TypeLowering.cpp +++ b/lib/SIL/TypeLowering.cpp @@ -338,6 +338,8 @@ namespace { case ExistentialRepresentation::Metatype: return asImpl().handleTrivial(type); } + + llvm_unreachable("Unhandled ExistentialRepresentation in switch."); } RetTy visitProtocolType(CanProtocolType type) { return visitExistentialType(type); @@ -1210,8 +1212,8 @@ TypeConverter::~TypeConverter() { void *TypeLowering::operator new(size_t size, TypeConverter &tc, IsDependent_t dependent) { return dependent - ? tc.DependentBPA.Allocate(size, alignof(TypeLowering)) - : tc.IndependentBPA.Allocate(size, alignof(TypeLowering)); + ? tc.DependentBPA.Allocate(size, alignof(TypeLowering&)) + : tc.IndependentBPA.Allocate(size, alignof(TypeLowering&)); } const TypeLowering *TypeConverter::find(TypeKey k) { @@ -1812,6 +1814,8 @@ CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) { return getIVarInitDestroyerInterfaceType(cast(vd), c.isForeign, Context, true); } + + llvm_unreachable("Unhandled SILDeclRefKind in switch."); } /// Get the generic environment for an entity. @@ -1858,6 +1862,8 @@ TypeConverter::getConstantGenericEnvironment(SILDeclRef c) { // Use the generic environment of the containing type. return c.getDecl()->getDeclContext()->getGenericEnvironmentOfContext(); } + + llvm_unreachable("Unhandled SILDeclRefKind in switch."); } SILType TypeConverter::getSubstitutedStorageType(AbstractStorageDecl *value,