Uploaded image for project: 'Swift'
  1. Swift
  2. SR-8192

Compiler crashes when `enum` has some `Range`s as associated values and has a certain mutating function in conditional extension.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
    • Environment:
      • OS
        • macOS 10.13.5
        • Ubuntu 16.04
      • Swift
        • Swift 4.1.2

      Description

      The code below will make the compiler crash.

      [Code]

      protocol P: Comparable {}
      
      enum BoundedRange<T> where T: Comparable {
        case empty
        case closedRange(ClosedRange<T>)
        case range(Range<T>)
      }
      
      extension BoundedRange where T: P {
        mutating func f() { self = .empty }
      }
      

       

      [Result on macOS]

      0  swift                    0x0000000108831fea PrintStackTraceSignalHandler(void*) + 42
      1  swift                    0x00000001088313a6 SignalHandler(int) + 966
      2  libsystem_platform.dylib 0x00007fff79fc2f5a _sigtramp + 26
      3  libsystem_malloc.dylib   0x00007fff79e5e342 tiny_malloc_from_free_list + 431
      4  swift                    0x00000001070ebacc llvm::BitcodeWriter::writeModule(llvm::Module const*, bool, llvm::ModuleSummaryIndex const*, bool, std::__1::array<unsigned int, 5ul>*) + 5500
      5  swift                    0x000000010711b5b9 llvm::WriteBitcodeToFile(llvm::Module const*, llvm::raw_ostream&, bool, llvm::ModuleSummaryIndex const*, bool, std::__1::array<unsigned int, 5ul>*) + 1385
      6  swift                    0x0000000105030bfc swift::performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine*, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, swift::version::Version const&, llvm::StringRef, swift::UnifiedStatsReporter*) + 204
      7  swift                    0x0000000104e93c1d performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 44685
      8  swift                    0x0000000104e87304 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7908
      9  swift                    0x0000000104e3bce5 main + 18917
      10 libdyld.dylib            0x00007fff79cb4015 start + 1
      11 libdyld.dylib            0x000000000000000f start + 2251603963
      Stack dump:
      0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file RangeEnum.swift -target x86_64-apple-darwin17.6.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name RangeEnum -o /var/folders/h1/hmh5ngpj37lgng38924vw0wm0000gn/T/RangeEnum-410c06.o 
      <unknown>:0: error: unable to execute command: Segmentation fault: 11
      <unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)
      

      [Result on Linux]

      swift: /home/buildnode/jenkins/workspace/oss-swift-4.1-package-linux-ubuntu-16_04/swift/lib/IRGen/LocalTypeData.h:231: llvm::Value *swift::irgen::LocalTypeDataCache::get(swift::irgen::IRGenFunction &, Key): Assertion `result && "get() on unmapped entry?"' failed.
      #0 0x0000000003f25074 PrintStackTraceSignalHandler(void*) (/opt/Swift-4.1.2/bin/swift+0x3f25074)
      #1 0x0000000003f253b6 SignalHandler(int) (/opt/Swift-4.1.2/bin/swift+0x3f253b6)
      #2 0x00007f530775e390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
      #3 0x00007f5305e9d428 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x35428)
      #4 0x00007f5305e9f02a abort (/lib/x86_64-linux-gnu/libc.so.6+0x3702a)
      #5 0x00007f5305e95bd7 (/lib/x86_64-linux-gnu/libc.so.6+0x2dbd7)
      #6 0x00007f5305e95c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
      #7 0x0000000000610a8f (/opt/Swift-4.1.2/bin/swift+0x610a8f)
      #8 0x0000000000627583 swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*) (/opt/Swift-4.1.2/bin/swift+0x627583)
      #9 0x00000000005732d2 swift::irgen::emitWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanType, llvm::Value**, swift::ProtocolConformanceRef) (/opt/Swift-4.1.2/bin/swift+0x5732d2)
      #10 0x0000000000573248 swift::irgen::emitWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanType, swift::ProtocolConformanceRef) (/opt/Swift-4.1.2/bin/swift+0x573248)
      #11 0x000000000054f173 void llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::callback_fn<(anonymous namespace)::GenericArguments::collect(swift::irgen::IRGenFunction&, swift::CanType)::{lambda(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)#1}>(long, unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) (/opt/Swift-4.1.2/bin/swift+0x54f173)
      #12 0x0000000000573f18 swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap const&, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) (/opt/Swift-4.1.2/bin/swift+0x573f18)
      #13 0x000000000054ed2d emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) (/opt/Swift-4.1.2/bin/swift+0x54ed2d)
      #14 0x000000000054cf32 llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(swift::CanType) (/opt/Swift-4.1.2/bin/swift+0x54cf32)
      #15 0x000000000053d973 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) (/opt/Swift-4.1.2/bin/swift+0x53d973)
      #16 0x000000000053dd9e llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRefForLayout, llvm::Value*>::visit<>(swift::CanType) (/opt/Swift-4.1.2/bin/swift+0x53dd9e)
      #17 0x000000000053dd0f swift::irgen::IRGenFunction::emitTypeMetadataRefForLayout(swift::SILType) (/opt/Swift-4.1.2/bin/swift+0x53dd0f)
      #18 0x0000000000589b3f (anonymous namespace)::StructNonFixedOffsets::getOffsetForIndex(swift::irgen::IRGenFunction&, unsigned int) (/opt/Swift-4.1.2/bin/swift+0x589b3f)
      #19 0x0000000000617a34 swift::irgen::ElementLayout::project(swift::irgen::IRGenFunction&, swift::irgen::Address, llvm::Optional<swift::irgen::NonFixedOffsetsImpl*>, llvm::Twine const&) const (/opt/Swift-4.1.2/bin/swift+0x617a34)
      #20 0x0000000000589a33 swift::irgen::RecordField<(anonymous namespace)::StructFieldInfo>::projectAddress(swift::irgen::IRGenFunction&, swift::irgen::Address, llvm::Optional<swift::irgen::NonFixedOffsetsImpl*>) const (/opt/Swift-4.1.2/bin/swift+0x589a33)
      #21 0x000000000058f855 swift::irgen::RecordTypeInfoImpl<(anonymous namespace)::NonFixedStructTypeInfo, swift::irgen::WitnessSizedTypeInfo<(anonymous namespace)::NonFixedStructTypeInfo>, (anonymous namespace)::StructFieldInfo, false>::destroy(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::SILType, bool) const (/opt/Swift-4.1.2/bin/swift+0x58f855)
      #22 0x0000000000516198 std::_Function_handler<void (unsigned int, swift::irgen::EnumImplStrategy::Element), (anonymous namespace)::MultiPayloadEnumImplStrategy::destroy(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::SILType, bool) const::{lambda(unsigned int, swift::irgen::EnumImplStrategy::Element)#1}>::_M_invoke(std::_Any_data const&, unsigned int&&, swift::irgen::EnumImplStrategy::Element&&) (/opt/Swift-4.1.2/bin/swift+0x516198)
      #23 0x0000000000511622 (anonymous namespace)::MultiPayloadEnumImplStrategy::forNontrivialPayloads(swift::irgen::IRGenFunction&, llvm::Value*, std::function<void (unsigned int, swift::irgen::EnumImplStrategy::Element)>) const (/opt/Swift-4.1.2/bin/swift+0x511622)
      #24 0x000000000050e527 (anonymous namespace)::MultiPayloadEnumImplStrategy::destroy(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::SILType, bool) const (/opt/Swift-4.1.2/bin/swift+0x50e527)
      #25 0x00000000004f897e void llvm::function_ref<void (swift::irgen::IRGenFunction&)>::callback_fn<swift::irgen::IRGenModule::generateCallToOutlinedDestroy(swift::irgen::IRGenFunction&, swift::irgen::TypeInfo const&, swift::irgen::Address, swift::SILType, llvm::MapVector<swift::CanType, llvm::Value*, llvm::DenseMap<swift::CanType, unsigned int, llvm::DenseMapInfo<swift::CanType>, llvm::detail::DenseMapPair<swift::CanType, unsigned int> >, std::vector<std::pair<swift::CanType, llvm::Value*>, std::allocator<std::pair<swift::CanType, llvm::Value*> > > > const*)::$_6>(long, swift::irgen::IRGenFunction&) (/opt/Swift-4.1.2/bin/swift+0x4f897e)
      #26 0x00000000004efaaa swift::irgen::IRGenModule::getOrCreateHelperFunction(llvm::StringRef, llvm::Type*, llvm::ArrayRef<llvm::Type*>, llvm::function_ref<void (swift::irgen::IRGenFunction&)>, bool) (/opt/Swift-4.1.2/bin/swift+0x4efaaa)
      #27 0x00000000004f07f6 swift::irgen::IRGenModule::generateCallToOutlinedDestroy(swift::irgen::IRGenFunction&, swift::irgen::TypeInfo const&, swift::irgen::Address, swift::SILType, llvm::MapVector<swift::CanType, llvm::Value*, llvm::DenseMap<swift::CanType, unsigned int, llvm::DenseMapInfo<swift::CanType>, llvm::detail::DenseMapPair<swift::CanType, unsigned int> >, std::vector<std::pair<swift::CanType, llvm::Value*>, std::allocator<std::pair<swift::CanType, llvm::Value*> > > > const*) (/opt/Swift-4.1.2/bin/swift+0x4f07f6)
      #28 0x000000000050e465 (anonymous namespace)::MultiPayloadEnumImplStrategy::destroy(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::SILType, bool) const (/opt/Swift-4.1.2/bin/swift+0x50e465)
      #29 0x00000000005166d5 (anonymous namespace)::MultiPayloadEnumImplStrategy::emitIndirectAssign(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType, swift::IsTake_t, bool) const (/opt/Swift-4.1.2/bin/swift+0x5166d5)
      #30 0x000000000050e99c (anonymous namespace)::MultiPayloadEnumImplStrategy::assignWithTake(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType, bool) const (/opt/Swift-4.1.2/bin/swift+0x50e99c)
      #31 0x0000000000506084 (anonymous namespace)::EnumTypeInfoBase<swift::irgen::WitnessSizedTypeInfo<(anonymous namespace)::NonFixedEnumTypeInfo> >::assignWithTake(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType, bool) const (/opt/Swift-4.1.2/bin/swift+0x506084)
      #32 0x00000000004f8b73 void llvm::function_ref<void (swift::irgen::TypeInfo const&, swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType)>::callback_fn<swift::irgen::IRGenModule::getOrCreateOutlinedAssignWithTakeFunction(swift::irgen::TypeInfo const&, llvm::Type*, swift::SILType, llvm::MapVector<swift::CanType, llvm::Value*, llvm::DenseMap<swift::CanType, unsigned int, llvm::DenseMapInfo<swift::CanType>, llvm::detail::DenseMapPair<swift::CanType, unsigned int> >, std::vector<std::pair<swift::CanType, llvm::Value*>, std::allocator<std::pair<swift::CanType, llvm::Value*> > > > const*)::$_10>(long, swift::irgen::TypeInfo const&, swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType) (/opt/Swift-4.1.2/bin/swift+0x4f8b73)
      #33 0x00000000004f8a82 void llvm::function_ref<void (swift::irgen::IRGenFunction&)>::callback_fn<swift::irgen::IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction(swift::irgen::TypeInfo const&, llvm::Type*, swift::SILType, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, llvm::function_ref<void (swift::irgen::TypeInfo const&, swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType)>, llvm::MapVector<swift::CanType, llvm::Value*, llvm::DenseMap<swift::CanType, unsigned int, llvm::DenseMapInfo<swift::CanType>, llvm::detail::DenseMapPair<swift::CanType, unsigned int> >, std::vector<std::pair<swift::CanType, llvm::Value*>, std::allocator<std::pair<swift::CanType, llvm::Value*> > > > const*)::$_7>(long, swift::irgen::IRGenFunction&) (/opt/Swift-4.1.2/bin/swift+0x4f8a82)
      #34 0x00000000004efaaa swift::irgen::IRGenModule::getOrCreateHelperFunction(llvm::StringRef, llvm::Type*, llvm::ArrayRef<llvm::Type*>, llvm::function_ref<void (swift::irgen::IRGenFunction&)>, bool) (/opt/Swift-4.1.2/bin/swift+0x4efaaa)
      #35 0x00000000004f0dbe swift::irgen::IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction(swift::irgen::TypeInfo const&, llvm::Type*, swift::SILType, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, llvm::function_ref<void (swift::irgen::TypeInfo const&, swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType)>, llvm::MapVector<swift::CanType, llvm::Value*, llvm::DenseMap<swift::CanType, unsigned int, llvm::DenseMapInfo<swift::CanType>, llvm::detail::DenseMapPair<swift::CanType, unsigned int> >, std::vector<std::pair<swift::CanType, llvm::Value*>, std::allocator<std::pair<swift::CanType, llvm::Value*> > > > const*) (/opt/Swift-4.1.2/bin/swift+0x4f0dbe)
      #36 0x00000000004f1963 swift::irgen::IRGenModule::getOrCreateOutlinedAssignWithTakeFunction(swift::irgen::TypeInfo const&, llvm::Type*, swift::SILType, llvm::MapVector<swift::CanType, llvm::Value*, llvm::DenseMap<swift::CanType, unsigned int, llvm::DenseMapInfo<swift::CanType>, llvm::detail::DenseMapPair<swift::CanType, unsigned int> >, std::vector<std::pair<swift::CanType, llvm::Value*>, std::allocator<std::pair<swift::CanType, llvm::Value*> > > > const*) (/opt/Swift-4.1.2/bin/swift+0x4f1963)
      #37 0x00000000004f01e0 swift::irgen::IRGenModule::generateCallToOutlinedCopyAddr(swift::irgen::IRGenFunction&, swift::irgen::TypeInfo const&, swift::irgen::Address, swift::irgen::Address, swift::SILType, llvm::Constant* (swift::irgen::IRGenModule::*)(swift::irgen::TypeInfo const&, llvm::Type*, swift::SILType, llvm::MapVector<swift::CanType, llvm::Value*, llvm::DenseMap<swift::CanType, unsigned int, llvm::DenseMapInfo<swift::CanType>, llvm::detail::DenseMapPair<swift::CanType, unsigned int> >, std::vector<std::pair<swift::CanType, llvm::Value*>, std::allocator<std::pair<swift::CanType, llvm::Value*> > > > const*), llvm::MapVector<swift::CanType, llvm::Value*, llvm::DenseMap<swift::CanType, unsigned int, llvm::DenseMapInfo<swift::CanType>, llvm::detail::DenseMapPair<swift::CanType, unsigned int> >, std::vector<std::pair<swift::CanType, llvm::Value*>, std::allocator<std::pair<swift::CanType, llvm::Value*> > > > const*) (/opt/Swift-4.1.2/bin/swift+0x4f01e0)
      #38 0x000000000050e95c (anonymous namespace)::MultiPayloadEnumImplStrategy::assignWithTake(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType, bool) const (/opt/Swift-4.1.2/bin/swift+0x50e95c)
      #39 0x0000000000506084 (anonymous namespace)::EnumTypeInfoBase<swift::irgen::WitnessSizedTypeInfo<(anonymous namespace)::NonFixedEnumTypeInfo> >::assignWithTake(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType, bool) const (/opt/Swift-4.1.2/bin/swift+0x506084)
      #40 0x00000000005e4c23 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) (/opt/Swift-4.1.2/bin/swift+0x5e4c23)
      #41 0x00000000005d6242 (anonymous namespace)::IRGenSILFunction::emitSILFunction() (/opt/Swift-4.1.2/bin/swift+0x5d6242)
      #42 0x00000000005d3d3b swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) (/opt/Swift-4.1.2/bin/swift+0x5d3d3b)
      #43 0x00000000004e5ae5 swift::irgen::IRGenerator::emitGlobalTopLevel() (/opt/Swift-4.1.2/bin/swift+0x4e5ae5)
      #44 0x00000000005ad77f performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) (/opt/Swift-4.1.2/bin/swift+0x5ad77f)
      #45 0x00000000005adff7 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, unsigned int, llvm::GlobalVariable**) (/opt/Swift-4.1.2/bin/swift+0x5adff7)
      #46 0x00000000004c36c7 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) (/opt/Swift-4.1.2/bin/swift+0x4c36c7)
      #47 0x00000000004beecc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/opt/Swift-4.1.2/bin/swift+0x4beecc)
      #48 0x00000000004778c4 main (/opt/Swift-4.1.2/bin/swift+0x4778c4)
      #49 0x00007f5305e88830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830)
      #50 0x0000000000475179 _start (/opt/Swift-4.1.2/bin/swift+0x475179)
      Stack dump:
      0.	Program arguments: /opt/Swift-4.1.2/bin/swift -frontend -c -primary-file RangeEnum.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name RangeEnum -o /tmp/RangeEnum-951e24.o 
      1.	While emitting IR SIL function "@_T09RangeEnum07BoundedA0OA2A1PRzrlE1fyyF".
       for 'f()' at RangeEnum.swift:10:12
      <unknown>:0: error: unable to execute command: Aborted
      <unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
      

      [Notes]

      • The compiler does not crash when
        • "self = .empty" is removed.
        • "case closedRange(ClosedRange<T>)" or "case range(Range<T>)" is removed.
        • "where T: P" is removed
      • The compiler does also crash when
        • Replace "mutating func f()" with "init()"

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              YOCKOW Knock YOCKOW
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: