swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.51k stars 10.35k forks source link

[SR-10773] Regression: Segmentation fault: 11 compiling code in swift 5.0.1 #53163

Closed swift-ci closed 4 years ago

swift-ci commented 5 years ago
Previous ID SR-10773
Radar None
Original Reporter ryanmaxwell (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment compile working: Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1) Target: x86_64-apple-darwin18.6.0 compile failing: Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5) Target: x86_64-apple-darwin18.6.0
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, 5.0Regression, CompilerCrash | |Assignee | None | |Priority | Medium | md5: 928d2027e39050ee0304bb6b545fec7b

duplicates:

Issue Description:

The following code compiles with swift 4.2 compiler, but crashes swift 5.0.1.

import Foundation

public protocol Model {}

protocol ModelManager {
 associatedtype Element: Model

func doRequest(completion: @escaping (Error?) -> Void)
}

extension ModelManager {
 func doRequest(completion: @escaping (Error?) -> Void) {

}
}

public class InMemoryManager<Element:Model>: ModelManager {

}

Output:

swiftc BadCode.swift 
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file BadCode.swift -target x86_64-apple-darwin18.6.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name BadCode -o /var/folders/bv/11123yb90dvgk104vk6l97y80000gn/T/BadCode-797ec5.o 
1.  While emitting IR SIL function "@$s7BadCode15InMemoryManagerCyqd__GAA05ModelE0A2aEP9doRequest10completionyys5Error_pSgc_tFTW".
 for 'doRequest(completion:)' (at BadCode.swift:15:5)
0  swift                    0x000000010d90fee3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010d90f6bc SignalHandler(int) + 348
2  libsystem_platform.dylib 0x00007fff67978b5d _sigtramp + 29
3  swift                    0x000000010ad3ce71 swift::AccessLevelRequest::OutputType swift::evaluateOrDefault<swift::AccessLevelRequest>(swift::Evaluator&, swift::AccessLevelRequest, swift::AccessLevelRequest::OutputType) + 721
4  swift                    0x00000001097bd031 swift::irgen::FulfillmentMap::searchWitnessTable(swift::irgen::IRGenModule&, swift::CanType, swift::ProtocolDecl*, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>*) + 65
5  swift                    0x00000001097bcfa2 swift::irgen::FulfillmentMap::searchWitnessTable(swift::irgen::IRGenModule&, swift::CanType, swift::ProtocolDecl*, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) + 450
6  swift                    0x00000001097bcda8 void llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::callback_fn<swift::irgen::FulfillmentMap::searchNominalTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, swift::MetadataState, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&)::$_1>(long, unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) + 1656
7  swift                    0x000000010990d8cf swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) + 335
8  swift                    0x00000001097bbf5a swift::irgen::FulfillmentMap::searchNominalTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, swift::MetadataState, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) + 490
9  swift                    0x00000001097bbd38 swift::irgen::FulfillmentMap::searchTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, swift::irgen::IsExact_t, swift::MetadataState, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) + 952
10 swift                    0x00000001099ba4fa swift::irgen::IRGenFunction::bindLocalTypeDataFromTypeMetadata(swift::CanType, swift::irgen::IsExact_t, llvm::Value*, swift::MetadataState) + 314
11 swift                    0x000000010990b264 swift::irgen::emitPolymorphicParameters(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::Explosion&, swift::irgen::WitnessMetadata*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 580
12 swift                    0x0000000109972311 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8049
13 swift                    0x00000001098314c9 swift::irgen::IRGenerator::emitLazyDefinitions() + 1353
14 swift                    0x00000001099524b0 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1232
15 swift                    0x0000000109774319 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 49433
16 swift                    0x000000010976492e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6862
17 swift                    0x00000001097029ce main + 1246
18 libdyld.dylib            0x00007fff6778d3d5 start + 1
<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)
belkadan commented 5 years ago

With asserts, on master:

Assertion failed: (is<T>() && "Invalid accessor called"), function get, file /Volumes/Data/swift-public/llvm/include/llvm/ADT/PointerUnion.h, line 136.
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-darwin18.6.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode10.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--cf11b8.o 
1.  Swift version 5.0-dev (LLVM f0b886e419, Swift e5a4b40381)
2.  While generating protocol witness thunk SIL function "@$s4main15InMemoryManagerCyqd__GAA05ModelD0A2aEP9doRequest10completionyys5Error_pSgc_tFTW".
 for 'doRequest(completion:)' (at <stdin>:12:2)
0  swift                    0x00000001139dda35 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001139dccf5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001139de018 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff6fd8db5d _sigtramp + 29
4  libsystem_platform.dylib 0x00007ffedfd33ee0 _sigtramp + 1878680480
5  libsystem_c.dylib        0x00007fff6fc476a6 abort + 127
6  libsystem_c.dylib        0x00007fff6fc1020d basename_r + 0
7  swift                    0x00000001102b5833 swift::Lowering::SILGenModule::useConformance(swift::ProtocolConformanceRef) + 803
8  swift                    0x00000001102b55bc swift::Lowering::SILGenModule::useConformance(swift::ProtocolConformanceRef) + 172
9  swift                    0x00000001102b5e66 swift::SILInstructionVisitor<LazyConformanceEmitter, void>::visit(swift::SILInstruction*) + 1062
10 swift                    0x00000001102b59e3 swift::Lowering::SILGenModule::emitLazyConformancesForFunction(swift::SILFunction*) + 99
11 swift                    0x00000001103093eb swift::Lowering::SILGenModule::emitProtocolWitness(swift::ProtocolConformanceRef, swift::SILLinkage, swift::IsSerialized_t, swift::SILDeclRef, swift::SILDeclRef, swift::Lowering::IsFreeFunctionWitness_t, swift::Witness) + 1963
12 swift                    0x000000011030b73b (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethodImplementation(swift::SILDeclRef, swift::SILDeclRef, swift::Witness) + 283
13 swift                    0x000000011030b563 (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethod(swift::SILDeclRef) + 387
14 swift                    0x000000011030b0e3 swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) + 1507
15 swift                    0x0000000110308766 swift::Lowering::SILGenModule::getWitnessTable(swift::NormalProtocolConformance*) + 310
16 swift                    0x000000011030a7cf (anonymous namespace)::SILGenType::emitType() + 1983
17 swift                    0x000000011030a009 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 25
18 swift                    0x0000000110228312 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 818
19 swift                    0x0000000110229305 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 293
20 swift                    0x0000000110229879 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&) + 41
21 swift                    0x000000010ff260dd performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 8365
22 swift                    0x000000010ff22fd2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2978
23 swift                    0x000000010fec9d39 main + 729
24 libdyld.dylib            0x00007fff6fba23d5 start + 1
25 libdyld.dylib            0x000000000000000f start + 2420497467
belkadan commented 5 years ago

@slavapestov, @rjmccall, did we have one of these already?

slavapestov commented 5 years ago

Wait, the 5.0 crash is SR-8814. However the master crash is a new regression! Let's use this JIRA to track the latter.

Thanks ryanmaxwell (JIRA User) and @belkadan!