Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-8192] Compiler crashes when enum has some Ranges as associated values and has a certain mutating function in conditional extension. #50724

Closed
YOCKOW opened this issue Jul 6, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@YOCKOW
Copy link
Collaborator

YOCKOW commented Jul 6, 2018

Previous ID SR-8192
Radar None
Original Reporter @YOCKOW
Type Bug
Status Resolved
Resolution Done
Environment
  • OS

    • macOS 10.13.5

    • Ubuntu 16.04

  • Swift

    • Swift 4.1.2
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: 7a4913bfdb07c7f33e6735936bedd827

Issue 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.
#&#8203;0 0x0000000003f25074 PrintStackTraceSignalHandler(void*) (/opt/Swift-4.1.2/bin/swift+0x3f25074)
#&#8203;1 0x0000000003f253b6 SignalHandler(int) (/opt/Swift-4.1.2/bin/swift+0x3f253b6)
#&#8203;2 0x00007f530775e390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#&#8203;3 0x00007f5305e9d428 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x35428)
#&#8203;4 0x00007f5305e9f02a abort (/lib/x86_64-linux-gnu/libc.so.6+0x3702a)
#&#8203;5 0x00007f5305e95bd7 (/lib/x86_64-linux-gnu/libc.so.6+0x2dbd7)
#&#8203;6 0x00007f5305e95c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
#&#8203;7 0x0000000000610a8f (/opt/Swift-4.1.2/bin/swift+0x610a8f)
#&#8203;8 0x0000000000627583 swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*) (/opt/Swift-4.1.2/bin/swift+0x627583)
#&#8203;9 0x00000000005732d2 swift::irgen::emitWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanType, llvm::Value**, swift::ProtocolConformanceRef) (/opt/Swift-4.1.2/bin/swift+0x5732d2)
#&#8203;10 0x0000000000573248 swift::irgen::emitWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanType, swift::ProtocolConformanceRef) (/opt/Swift-4.1.2/bin/swift+0x573248)
#&#8203;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)
#&#8203;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)
#&#8203;13 0x000000000054ed2d emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) (/opt/Swift-4.1.2/bin/swift+0x54ed2d)
#&#8203;14 0x000000000054cf32 llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(swift::CanType) (/opt/Swift-4.1.2/bin/swift+0x54cf32)
#&#8203;15 0x000000000053d973 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) (/opt/Swift-4.1.2/bin/swift+0x53d973)
#&#8203;16 0x000000000053dd9e llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRefForLayout, llvm::Value*>::visit<>(swift::CanType) (/opt/Swift-4.1.2/bin/swift+0x53dd9e)
#&#8203;17 0x000000000053dd0f swift::irgen::IRGenFunction::emitTypeMetadataRefForLayout(swift::SILType) (/opt/Swift-4.1.2/bin/swift+0x53dd0f)
#&#8203;18 0x0000000000589b3f (anonymous namespace)::StructNonFixedOffsets::getOffsetForIndex(swift::irgen::IRGenFunction&, unsigned int) (/opt/Swift-4.1.2/bin/swift+0x589b3f)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;24 0x000000000050e527 (anonymous namespace)::MultiPayloadEnumImplStrategy::destroy(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::SILType, bool) const (/opt/Swift-4.1.2/bin/swift+0x50e527)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;28 0x000000000050e465 (anonymous namespace)::MultiPayloadEnumImplStrategy::destroy(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::SILType, bool) const (/opt/Swift-4.1.2/bin/swift+0x50e465)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;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)
#&#8203;40 0x00000000005e4c23 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) (/opt/Swift-4.1.2/bin/swift+0x5e4c23)
#&#8203;41 0x00000000005d6242 (anonymous namespace)::IRGenSILFunction::emitSILFunction() (/opt/Swift-4.1.2/bin/swift+0x5d6242)
#&#8203;42 0x00000000005d3d3b swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) (/opt/Swift-4.1.2/bin/swift+0x5d3d3b)
#&#8203;43 0x00000000004e5ae5 swift::irgen::IRGenerator::emitGlobalTopLevel() (/opt/Swift-4.1.2/bin/swift+0x4e5ae5)
#&#8203;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)
#&#8203;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)
#&#8203;46 0x00000000004c36c7 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) (/opt/Swift-4.1.2/bin/swift+0x4c36c7)
#&#8203;47 0x00000000004beecc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/opt/Swift-4.1.2/bin/swift+0x4beecc)
#&#8203;48 0x00000000004778c4 main (/opt/Swift-4.1.2/bin/swift+0x4778c4)
#&#8203;49 0x00007f5305e88830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830)
#&#8203;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()"
@belkadan
Copy link
Contributor

belkadan commented Jul 6, 2018

Seems to be fixed in Swift 4.2!

@YOCKOW
Copy link
Collaborator Author

YOCKOW commented Jul 8, 2018

I'm sorry I have passed over Swift 4.2.

Thank you for pointing that out.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

3 participants