swiftlang / swift

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

[SR-4417] Compiler crashes when get value from enum specific case. #46994

Open swift-ci opened 7 years ago

swift-ci commented 7 years ago
Previous ID SR-4417
Radar None
Original Reporter tarunon (JIRA User)
Type Bug
Environment Swift 3.1, Xcode 8.3, Playground
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, 3.1Regression, CompilerCrash, RunTimeCrash | |Assignee | None | |Priority | Medium | md5: f96eedb557b7078d00aa8ca0ee2987ef

relates to:

Issue Description:

1. Make a `enum` that have some case contain associated value.

  1. Get associated value using `switch` via type casting to `protocol` (or associated value defined `protocol`).
  2. Add other pattern into same case.

Minimum code is here.

protocol X {}
extension String: X {}

enum A {
    case hoge(X)
    case fuga(X)
}

let a = A.hoge("hello")

switch a {
case .hoge(let x), .fuga(let x):
    print(x)
default:
    break
}
belkadan commented 7 years ago

Backtrace on master:

Assertion failed: (!v->getType().isAddress()), function emitCopyValueOperation, file /Volumes/Data/swift-public/swift/include/swift/SIL/SILBuilder.h, line 1684.
0  swift                    0x00000001102fd108 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x00000001102fc326 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x00000001102fd759 SignalHandler(int) + 361
3  libsystem_platform.dylib 0x00007fff92992b3a _sigtramp + 26
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 1835455712
5  libsystem_c.dylib        0x00007fff92817420 abort + 129
6  libsystem_c.dylib        0x00007fff927de893 basename_r + 0
7  swift                    0x000000010d9501ea void llvm::function_ref<void ((anonymous namespace)::PatternMatchEmission&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, (anonymous namespace)::ClauseRow&)>::callback_fn<swift::Lowering::SILGenFunction::emitSwitchStmt(swift::SwitchStmt*)::$_1>(long, (anonymous namespace)::PatternMatchEmission&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, (anonymous namespace)::ClauseRow&) + 1466
8  swift                    0x000000010d945fc2 (anonymous namespace)::PatternMatchEmission::emitDispatch((anonymous namespace)::ClauseMatrix&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, std::__1::function<void (swift::SILLocation)> const&) + 3122
9  swift                    0x000000010d94d216 std::__1::__function::__func<(anonymous namespace)::PatternMatchEmission::emitSpecializedDispatch((anonymous namespace)::ClauseMatrix&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, unsigned int&, unsigned int, std::__1::function<void (swift::SILLocation)> const&)::$_7, std::__1::allocator<(anonymous namespace)::PatternMatchEmission::emitSpecializedDispatch((anonymous namespace)::ClauseMatrix&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, unsigned int&, unsigned int, std::__1::function<void (swift::SILLocation)> const&)::$_7>, void (llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, llvm::ArrayRef<(anonymous namespace)::SpecializedRow>, std::__1::function<void (swift::SILLocation)> const&)>::operator()(llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>&&, llvm::ArrayRef<(anonymous namespace)::SpecializedRow>&&, std::__1::function<void (swift::SILLocation)> const&) + 1926
10 swift                    0x000000010d94a176 (anonymous namespace)::PatternMatchEmission::emitSpecializedDispatch((anonymous namespace)::ClauseMatrix&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, unsigned int&, unsigned int, std::__1::function<void (swift::SILLocation)> const&) + 9462
11 swift                    0x000000010d94593a (anonymous namespace)::PatternMatchEmission::emitDispatch((anonymous namespace)::ClauseMatrix&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, std::__1::function<void (swift::SILLocation)> const&) + 1450
12 swift                    0x000000010d944c65 swift::Lowering::SILGenFunction::emitSwitchStmt(swift::SwitchStmt*) + 2117
13 swift                    0x000000010d96a295 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21

@gottesmm, you were going to attack pattern-matching soon anyway, right?

belkadan commented 7 years ago

(without assertions we get through compilation but then crash at run time)

gottesmm commented 7 years ago

@belkadan In the next little bit. I have patches on master that are behind a flag.

gottesmm commented 7 years ago

I am fixing 1 thing before I get back to it.