From 8a7fcf46f70e55730fb4236f6cf5089751d191f1 Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Thu, 17 Nov 2016 17:47:22 +0000 Subject: [PATCH] Fix errors and warnings building swift/IRGen on Windows using MSVC --- lib/IRGen/GenCall.cpp | 2 ++ lib/IRGen/GenClangType.cpp | 4 ++++ lib/IRGen/GenEnum.cpp | 10 ++++++++-- lib/IRGen/GenHeap.cpp | 2 ++ lib/IRGen/GenMeta.cpp | 14 ++++++++++++++ lib/IRGen/GenProto.cpp | 2 ++ lib/IRGen/GenType.cpp | 8 +++++++- lib/IRGen/IRGenModule.cpp | 1 + lib/IRGen/IRGenModule.h | 2 ++ lib/IRGen/IRGenSIL.cpp | 4 ++++ lib/IRGen/MetadataPath.h | 4 ++-- lib/IRGen/TypeInfo.h | 2 ++ lib/LLVMPasses/LLVMSwiftAA.cpp | 2 ++ 13 files changed, 52 insertions(+), 5 deletions(-) diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 5b7477433b604..e1f6657d363fe 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -317,6 +317,8 @@ llvm::Type *SignatureExpansion::expandDirectResult() { return schema.getScalarResultType(IGM); } } + + llvm_unreachable("Not a valid SILFunctionLanguage."); } static const clang::FieldDecl * diff --git a/lib/IRGen/GenClangType.cpp b/lib/IRGen/GenClangType.cpp index cebefec97e5b8..c4299e0e9431c 100644 --- a/lib/IRGen/GenClangType.cpp +++ b/lib/IRGen/GenClangType.cpp @@ -82,6 +82,8 @@ getClangBuiltinTypeFromKind(const clang::ASTContext &context, return context.SingletonId; #include "clang/Basic/OpenCLImageTypes.def" } + + llvm_unreachable("Not a valid BuiltinType."); } static clang::CanQualType getClangSelectorType( @@ -490,6 +492,8 @@ GenClangType::visitBoundGenericType(CanBoundGenericType type) { return getCanonicalType(fnPtrTy); } } + + llvm_unreachable("Not a valid StructKind."); } clang::CanQualType GenClangType::visitEnumType(CanEnumType type) { diff --git a/lib/IRGen/GenEnum.cpp b/lib/IRGen/GenEnum.cpp index 82a97af610811..f261790983c2a 100644 --- a/lib/IRGen/GenEnum.cpp +++ b/lib/IRGen/GenEnum.cpp @@ -950,7 +950,9 @@ namespace { unsigned getFixedExtraInhabitantCount(IRGenModule &IGM) const override { unsigned bits = cast(TI)->getFixedSize().getValueInBits(); assert(bits < 32 && "freakishly huge no-payload enum"); - return (1U << bits) - ElementsWithNoPayload.size(); + + size_t shifted = static_cast(static_cast(1) << bits); + return shifted - ElementsWithNoPayload.size(); } APInt getFixedExtraInhabitantValue(IRGenModule &IGM, @@ -2088,6 +2090,8 @@ namespace { case Normal: llvm_unreachable("not a refcounted payload"); } + + llvm_unreachable("Not a valid CopyDestroyStrategy"); } void retainRefcountedPayload(IRGenFunction &IGF, @@ -2960,6 +2964,8 @@ namespace { case Normal: llvm_unreachable("not a refcounted payload"); } + + llvm_unreachable("Not a valid CopyDestroyStrategy."); } void retainRefcountedPayload(IRGenFunction &IGF, @@ -5669,7 +5675,7 @@ const TypeInfo *TypeConverter::convertEnumType(TypeBase *key, CanType type, } auto tagBits = strategy->getTagBitsForPayloads(); assert(tagBits.count() >= 32 - || (1U << tagBits.count()) + || static_cast(static_cast(1) << tagBits.count()) >= strategy->getElementsWithPayload().size()); DEBUG(llvm::dbgs() << " payload tag bits:\t"; displayBitMask(tagBits)); diff --git a/lib/IRGen/GenHeap.cpp b/lib/IRGen/GenHeap.cpp index 6f5ae5d2622da..35c4d140c77ff 100644 --- a/lib/IRGen/GenHeap.cpp +++ b/lib/IRGen/GenHeap.cpp @@ -1041,6 +1041,8 @@ llvm::Type *IRGenModule::getReferenceType(ReferenceCounting refcounting) { case ReferenceCounting::Error: return ErrorPtrTy; } + + llvm_unreachable("Not a valid ReferenceCounting."); } #define DEFINE_BINARY_OPERATION(KIND, RESULT, TYPE1, TYPE2) \ diff --git a/lib/IRGen/GenMeta.cpp b/lib/IRGen/GenMeta.cpp index 3e01b4f4eaaa7..bca976d0721ec 100644 --- a/lib/IRGen/GenMeta.cpp +++ b/lib/IRGen/GenMeta.cpp @@ -1679,6 +1679,8 @@ namespace { // All block types look like Builtin.UnknownObject. return emitDirectMetadataRef(C.TheUnknownObjectType); } + + llvm_unreachable("Not a valid SILFunctionType."); } llvm::Value *visitAnyMetatypeType(CanAnyMetatypeType type) { @@ -1704,6 +1706,8 @@ namespace { // FIXME: It'd be nice not to need a runtime call here. return IGF.emitTypeMetadataRef(type); } + + llvm_unreachable("Not a valid MetatypeRepresentation."); } /// Try to find the metatype in local data. @@ -1858,6 +1862,8 @@ namespace { // All block types look like Builtin.UnknownObject. return emitFromValueWitnessTable(C.TheUnknownObjectType); } + + llvm_unreachable("Not a valid SILFunctionType."); } llvm::Value *visitAnyMetatypeType(CanAnyMetatypeType type) { @@ -1876,6 +1882,8 @@ namespace { return emitFromValueWitnessTable( CanMetatypeType::get(IGF.IGM.Context.TheNativeObjectType)); } + + llvm_unreachable("Not a valid MetatypeRepresentation."); } llvm::Value *visitAnyClassType(ClassDecl *classDecl) { @@ -1893,6 +1901,8 @@ namespace { case ReferenceCounting::Error: llvm_unreachable("classes shouldn't have this kind of refcounting"); } + + llvm_unreachable("Not a valid ReferenceCounting."); } llvm::Value *visitClassType(CanClassType type) { @@ -4481,6 +4491,8 @@ static llvm::Value *emitLoadOfHeapMetadataRef(IRGenFunction &IGF, return objcClass; } } + + llvm_unreachable("Not a valid IsaEncoding."); } /// Given an object of class type, produce the heap metadata reference @@ -5565,6 +5577,8 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) { case KnownProtocolKind::ErrorCodeProtocol: return SpecialProtocol::None; } + + llvm_unreachable("Not a valid KnownProtocolKind."); } namespace { diff --git a/lib/IRGen/GenProto.cpp b/lib/IRGen/GenProto.cpp index 8c0fabf63c3a1..a34e560220a74 100644 --- a/lib/IRGen/GenProto.cpp +++ b/lib/IRGen/GenProto.cpp @@ -1815,6 +1815,8 @@ bool irgen::hasPolymorphicParameters(CanSILFunctionType ty) { // Always carries polymorphic parameters for the Self type. return true; } + + llvm_unreachable("Not a valid SILFunctionTypeRepresentation."); } static diff --git a/lib/IRGen/GenType.cpp b/lib/IRGen/GenType.cpp index ab1e41544ceb7..d3cfe996e1501 100644 --- a/lib/IRGen/GenType.cpp +++ b/lib/IRGen/GenType.cpp @@ -311,8 +311,10 @@ FixedTypeInfo::getSpareBitExtraInhabitantIndex(IRGenFunction &IGF, llvm::Value *spareIdx = emitGatherSpareBits(IGF, SpareBits, val, numOccupiedBits, 31); // Unbias by subtracting one. + + uint64_t shifted = static_cast(1 << numOccupiedBits); spareIdx = IGF.Builder.CreateSub(spareIdx, - llvm::ConstantInt::get(spareIdx->getType(), 1 << numOccupiedBits)); + llvm::ConstantInt::get(spareIdx->getType(), shifted)); idx = IGF.Builder.CreateOr(idx, spareIdx); } idx = IGF.Builder.CreateZExt(idx, IGF.IGM.Int32Ty); @@ -744,6 +746,8 @@ IRGenModule::getReferenceObjectTypeInfo(ReferenceCounting refcounting) { case ReferenceCounting::ObjC: llvm_unreachable("not implemented"); } + + llvm_unreachable("Not a valid ReferenceCounting."); } const LoadableTypeInfo &IRGenModule::getNativeObjectTypeInfo() { @@ -1817,6 +1821,8 @@ llvm::Value *IRGenFunction::getLocalSelfMetadata() { case ObjectReference: return emitDynamicTypeOfOpaqueHeapObject(*this, LocalSelf); } + + llvm_unreachable("Not a valid LocalSelfKind."); } void IRGenFunction::setLocalSelfMetadata(llvm::Value *value, diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 95c1489ad34fb..d7775b5c13559 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -378,6 +378,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen, // Only use the new calling conventions on platforms that support it. auto Arch = Triple.getArch(); + (void)Arch; if (SWIFT_RT_USE_RegisterPreservingCC && Arch == llvm::Triple::ArchType::aarch64) RegisterPreservingCC = SWIFT_LLVM_CC(RegisterPreservingCC); diff --git a/lib/IRGen/IRGenModule.h b/lib/IRGen/IRGenModule.h index 03eced5498c21..43e9f36388bfd 100644 --- a/lib/IRGen/IRGenModule.h +++ b/lib/IRGen/IRGenModule.h @@ -505,6 +505,8 @@ class IRGenModule { case ReferenceCounting::Error: llvm_unreachable("unowned references to this type are not supported"); } + + llvm_unreachable("Not a valid ReferenceCounting."); } /// Return the spare bit mask to use for types that comprise heap object diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 668202a164dd0..99a8605145976 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -1653,6 +1653,8 @@ static llvm::Value *getClassMetatype(IRGenFunction &IGF, case MetatypeRepresentation::ObjC: return emitHeapMetadataRefForHeapObject(IGF, baseValue, instanceType); } + + llvm_unreachable("Not a valid MetatypeRepresentation."); } void IRGenSILFunction::visitValueMetatypeInst(swift::ValueMetatypeInst *i) { @@ -2141,6 +2143,8 @@ getPartialApplicationFunction(IRGenSILFunction &IGF, SILValue v, return std::make_tuple(fn, context, fnType); } } + + llvm_unreachable("Not a valid SILFunctionType."); } void IRGenSILFunction::visitPartialApplyInst(swift::PartialApplyInst *i) { diff --git a/lib/IRGen/MetadataPath.h b/lib/IRGen/MetadataPath.h index 72069ffece8b9..f7694affa9916 100644 --- a/lib/IRGen/MetadataPath.h +++ b/lib/IRGen/MetadataPath.h @@ -186,10 +186,10 @@ class MetadataPath { for (auto C : Path) { switch (C.getKind()) { case Component::Kind::NominalParent: - Root = A.template createParent(Root); + Root = A.createParent(Root); continue; case Component::Kind::NominalTypeArgument: - Root = A.template createGenericArgument(C.getPrimaryIndex(), Root); + Root = A.createGenericArgument(C.getPrimaryIndex(), Root); continue; default: return nullptr; diff --git a/lib/IRGen/TypeInfo.h b/lib/IRGen/TypeInfo.h index 2333d07468d20..b498cfa186c36 100644 --- a/lib/IRGen/TypeInfo.h +++ b/lib/IRGen/TypeInfo.h @@ -202,6 +202,8 @@ class TypeInfo { "IsFixedSize vs IsAlwaysFixedSize mismatch"); return IsFixedSize_t(AlwaysFixedSize); } + + llvm_unreachable("Not a valid ResilienceExpansion."); } /// Whether this type is known to be loadable in the local diff --git a/lib/LLVMPasses/LLVMSwiftAA.cpp b/lib/LLVMPasses/LLVMSwiftAA.cpp index 5c99eba850419..1b5cc1b5892fa 100644 --- a/lib/LLVMPasses/LLVMSwiftAA.cpp +++ b/lib/LLVMPasses/LLVMSwiftAA.cpp @@ -28,6 +28,8 @@ static ModRefInfo getConservativeModRefForKind(const llvm::Instruction &I) { #define KIND(Name, MemBehavior) case RT_ ## Name: return MRI_ ## MemBehavior; #include "LLVMSwift.def" } + + llvm_unreachable("Not a valid Instruction."); } ModRefInfo SwiftAAResult::getModRefInfo(llvm::ImmutableCallSite CS,