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-10700] Compiler crash on switch using fallthrough and naming repetition #53097

Closed
swift-ci opened this issue May 16, 2019 · 1 comment
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10700
Radar None
Original Reporter hannesoid (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

Xcode 10.2, macOS 10.14.4 rMBP 15" 2014 and iMac Pro 10core 2017

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 3be73af7472a419ce5eb8ee581ff5d8c

duplicates:

  • SR-9698 Compiler crashes in switch with multiple binds and fallthroughs

Issue Description:

Run `swift SegFaultExample.swift` (attached fuke) in terminal multiple times.
Compiling this crashes my compiler every other time:

// Compilation sometimes leads to Segfault, or Abort
class SegFaultExample {

    struct Container {
        var state: State
        var entry: Entry

        enum State {
            case one
            case two(entry: Entry, foo: Foo, priority: Int) // removing  `, foo: Foo` fixes compilation issue(?)
        }
        struct Foo {}
        struct Entry {}
    }    

    func doSomething(foo: Container, otherCondition: Bool) {
        switch (foo.state, otherCondition) {
        case (.one, _):
            let entry = Container.Entry()  // renaming `entry` fixes compilation issue
            print(entry)
        case (.two(let entry, let foo, let priority), true) where priority > 2: // renaming `entry` fixes compilation issue
            fallthrough // remove fallthrough fixes compilation issue
        case (.two(let entry, let foo, let priority), false):
            print(entry)
            print(foo)
            print(priority)
        default:
            break
        }
    }
}

Originally Xcode usually complained about segfault 11❓. Compiled in terminal I encountered this:

swift ./SegFaultExample.swift
PHINode should have one entry for each predecessor of its parent basic block!
  %45 = phi i64 [ %38, %43 ], [ %0, %42 ], [ %15, %42 ], [ %38, %42 ], !dbg !126
PHI node operands are not the same type as the result!
  %45 = phi i64 [ %38, %43 ], [ %0, %42 ], [ %15, %42 ], [ %38, %42 ], !dbg !126
<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: Broken function found, compilation aborted!
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret ./SegFaultExample.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name SegFaultExample 
1.  Running pass 'Module Verifier' on function '@"$s15SegFaultExampleAAC11doSomething3foo14otherConditionyAB9ContainerV_SbtF"'
0  swift                    0x000000010802eee3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010802e6bc SignalHandler(int) + 348
2  libsystem_platform.dylib 0x00007fff6000bb5d _sigtramp + 29
3  libsystem_platform.dylib 0x00000001130edf87 _sigtramp + 3004048455
4  libsystem_c.dylib        0x00007fff5fecb6a6 abort + 127
5  swift                    0x0000000103e86cf8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)::$_1::__invoke(void*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) + 936
6  swift                    0x0000000107fdf826 llvm::report_fatal_error(llvm::Twine const&, bool) + 278
7  swift                    0x0000000107fdf70b llvm::report_fatal_error(char const*, bool) + 43
8  swift                    0x0000000107fa5c36 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) + 54
9  swift                    0x0000000107f4a5ed llvm::FPPassManager::runOnFunction(llvm::Function&) + 1613
10 swift                    0x0000000107f54afb llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 107
11 swift                    0x0000000107f54a25 llvm::legacy::FunctionPassManager::run(llvm::Function&) + 373
12 swift                    0x000000010406c408 swift::performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine*, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, swift::version::Version const&, llvm::StringRef, swift::UnifiedStatsReporter*) + 4632
13 swift                    0x00000001040717ca 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**) + 2026
14 swift                    0x000000010406ec6f swift::performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::GlobalVariable**) + 735
15 swift                    0x0000000103e93746 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 50502
16 swift                    0x0000000103e8392e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6862
17 swift                    0x0000000103e219ce main + 1246
18 libdyld.dylib            0x00007fff5fe263d5 start + 1
[1]    49274 abort      swift ./SegFaultExample.swift

I added comments how the crash can be worked-around. Interestingly it is fixed by renaming variable-names that are used in other parts aswell. The fallthrough seems to be involved, and the structure of the enum.

@belkadan
Copy link
Contributor

@gottesmm fixed this in Swift 5.1!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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
Projects
None yet
Development

No branches or pull requests

2 participants