swiftlang / swift

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

[SR-13835] Segmentation fault: 11 when compiling with names for associated values in enums #56233

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-13835
Radar rdar://problem/71166956
Original Reporter Quantm (JIRA User)
Type Bug
Environment I tried it with XCode 12.2 beta 3 and the release candidate. I'm using Swift 5.3. It's all running on a MacBook Pro 16 inch (2019) and Mac OS 11.0.1 RC
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, TypeChecker | |Assignee | None | |Priority | Medium | md5: 7896818b36c49ff0f3d11e791b814f39

Issue Description:

Hey,

I don't really know what information is needed for this, so sorry if something is missing. I'm getting a "Segmentation fault: 11" error when trying to compile my project. This is the stack dump:

Stack dump:
1.  Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
2.  While evaluating request IRGenSourceFileRequest(IR Generation for file "/Users/dennis/Code/App Projects/MyApp/MyApp/Scenes/TimelineOverview/TimelineDetailPresenter.swift")
3.  While emitting IR SIL function "@$s6MyApp6ScreenV16TimelineOverviewV0C15DetailPresenterC015moveEventsToNewC033_C3FD47DDD76AA9D6DD1DC064E098F94ELLyySayAA5EventV4InfoVGF".
 for 'moveEventsToNewTimeline(_:)' (at /Users/dennis/Code/App Projects/MyApp/MyApp/Scenes/TimelineOverview/TimelineDetailPresenter.swift:270:17)
4.  While converting type '(@callee_guaranteed (@in_guaranteed Timeline) -> ())'
0  swift                    0x000000010b3f6c15 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010b3f7332 SignalHandler(int) + 610
2  libsystem_platform.dylib 0x00007fff20383d7d _sigtramp + 29
3  libsystem_platform.dylib 0x00007ff9a7649430 _sigtramp + 18446744050207577808
4  swift                    0x0000000106fdcba7 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 13815
5  swift                    0x0000000106fd51e6 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8966
6  swift                    0x0000000106e85167 swift::irgen::IRGenerator::emitLazyDefinitions() + 1207
7  swift                    0x0000000106fafcc0 performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, swift::SourceFile*, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1920
8  swift                    0x0000000106fd2c51 swift::SimpleRequest<swift::IRGenSourceFileRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenSourceFileRequest const&, swift::Evaluator&) + 97
9  swift                    0x0000000106fb437c llvm::Expected<swift::IRGenSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenSourceFileRequest>(swift::IRGenSourceFileRequest const&) + 972
10 swift                    0x0000000106fb02fd swift::performIRGeneration(swift::IRGenOptions const&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 269
11 swift                    0x0000000106c0e822 performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 3042
12 swift                    0x0000000106bfe603 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 21363
13 swift                    0x0000000106b7f2c1 main + 1265
14 libdyld.dylib            0x00007fff2035a631 start + 1
15 libdyld.dylib            0x0000000000000081 start + 18446603339975776849
error: Segmentation fault: 11 (in target 'MyApp' from project 'MyApp')

This is the function that is referred to in the stack dump:

private func moveEventsToNewTimeline(_ infos: [Event.Info]) {
    // router refers to MyRouter above, the trigger just sets the enum to the specified case, basically. It's from XCoordinator: https://github.com/quickbirdstudios/XCoordinator but shouldn't be relevant
    router.trigger(.moveEventToNewTimeline(selectedTimelineHandler: { [weak self] newTimeline in
        // Even this empty closure produces the segmentation fault (sometimes)
    }))
}

enum MyRouter {
    case moveEventToNewTimeline(((Timeline) -> Void))
}

What solved the problem was removing the name for the associated value of the case. So, turning this

case moveEventToNewTimeline(selectedTimelineHandler: ((Timeline) -> Void))

into this

case moveEventToNewTimeline(((Timeline) -> Void))

resolves the problem (which was suggested here: https://stackoverflow.com/questions/63938592/segmentation-fault-11-xcode-swift-5-compile-issue). However, the crash hasn't always been occurring. I've had that name for the associated value for weeks without problems (I also use names for other associated values throughout the app and it never had a problem to compile).

Any ideas what happened here?

typesanitizer commented 4 years ago

@swift-ci create

aschwaighofer commented 4 years ago

Can you reproduce this issue in a project that contains only a subset of files that stubs out most of the code?

If so, can you attach such a project or file a bug on https://developer.apple.com/bug-reporting if you can share the project.

swift-ci commented 4 years ago

Comment by Dennis Müller (JIRA)

I'm not sure but I can give it a try.