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-4812] swiftc crash in swift::Lowering::SILGenFunction::emitClosureValue #47389

Closed
weissi opened this issue May 5, 2017 · 7 comments
Closed
Assignees
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

@weissi
Copy link
Member

weissi commented May 5, 2017

Previous ID SR-4812
Radar rdar://problem/40600800
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @slavapestov
Priority Medium

md5: 989a26d4b61afd91741e0078af477b2b

is duplicated by:

  • SR-9015 Code completion assertion failure: (D->hasValidSignature()), function getType, file swift/lib/Sema/ConstraintSystem.h
  • SR-10687 Swift compiler crash in swift::Lowering::SILGenFunction::emitClosureValue with calling higher function, variable, inner function

Issue Description:

For this non-sensical program

class X {
    public func foo() {
        let bar = { [weak self] in
            bar2()
        }
        func bar2() {
            bar()
        }
        bar()
    }
}

let x = X()
x.foo()

I get

0  swift                    0x00000001057544f7 PrintStackTraceSignalHandler(void*) + 39
1  swift                    0x00000001057539a6 SignalHandler(int) + 646
2  libsystem_platform.dylib 0x00007fffb48d7b3a _sigtramp + 26
3  libsystem_platform.dylib 0x000000000000000e _sigtramp + 1265796334
4  swift                    0x0000000102dd1bd3 swift::Lowering::SILGenFunction::emitClosureValue(swift::SILLocation, swift::SILDeclRef, swift::CanType, llvm::ArrayRef<swift::Substitution>) + 771
5  swift                    0x0000000102dc6112 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 194
6  swift                    0x0000000102dbb7d9 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 23001
7  swift                    0x0000000102db5c9c swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*) + 188
8  swift                    0x0000000102da36e6 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 198
9  swift                    0x0000000102e12ee8 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 14712
10 swift                    0x0000000102dd2509 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 409
11 swift                    0x0000000102d5389b swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 1867
12 swift                    0x0000000102d528a2 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 642
13 swift                    0x0000000102e17efb (anonymous namespace)::SILGenType::emitType() + 971
14 swift                    0x0000000102e17acd swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 29
15 swift                    0x0000000102d5fecb swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1483
16 swift                    0x0000000102d61aa9 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1593
17 swift                    0x0000000102572604 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 42516
18 swift                    0x0000000102521d6c main + 9052
19 libdyld.dylib            0x00007fffb46c8235 start + 1
20 libdyld.dylib            0x000000000000000f start + 1267957211

and

$ swift -version
Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)
Target: x86_64-apple-macosx10.9
@belkadan
Copy link
Contributor

belkadan commented May 8, 2017

I get the same on near-master. @slavapestov, look familiar?

@slavapestov
Copy link
Member

I'll take a look.

@slavapestov
Copy link
Member

So it crashes without the 'weak self' also. The problem is that 'bar' captures itself, via 'bar2', but 'bar' is not initialized yet when we form the reference to 'bar2'. I wonder if this should be prohibited.

@slavapestov
Copy link
Member

Note that this is not allowed:

let bar = { bar() }

@weissi
Copy link
Member Author

weissi commented Jul 13, 2017

still crashes now

$ ~/swift-source/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swiftc /tmp/foo.swift -o /tmp/foo
swift: /home/jweiss/swift-source/swift/lib/SILGen/SILGenFunction.cpp:201: void swift::Lowering::SILGenFunction::emitCaptures(swift::SILLocation, swift::AnyFunctionRef, swift::Lowering::CaptureEmission, SmallVectorImpl<swift::Lowering::ManagedValue> &): Assertion `found != VarLocs.end()' failed.
0  swift           0x0000000003acb188
1  swift           0x0000000003acb8c6
2  libpthread.so.0 0x00007fd049dce390
3  libc.so.6       0x00007fd0482f3428 gsignal + 56
4  libc.so.6       0x00007fd0482f502a abort + 362
5  libc.so.6       0x00007fd0482ebbd7
6  libc.so.6       0x00007fd0482ebc82
7  swift           0x0000000000c093fd
8  swift           0x0000000000c0984c
9  swift           0x0000000000c00f10
10 swift           0x0000000000bf4c59
11 swift           0x0000000000bf9152
12 swift           0x0000000000bebaa9
13 swift           0x0000000000bdb5f3
14 swift           0x0000000000bdb6dd
15 swift           0x0000000000c3f1b1
16 swift           0x0000000000c3effe
17 swift           0x0000000000c09ee8
18 swift           0x0000000000bbc55e
19 swift           0x0000000000bb4900
20 swift           0x0000000000c4849e
21 swift           0x0000000000c480f8
22 swift           0x0000000000bb9ceb
23 swift           0x0000000000bbac94
24 swift           0x0000000000bbb2cf
25 swift           0x00000000004aef78
26 swift           0x00000000004abfc1
27 swift           0x00000000004655f4
28 libc.so.6       0x00007fd0482de830 __libc_start_main + 240
29 swift           0x0000000000462eb9
Stack dump:
0.  Program arguments: /home/jweiss/swift-source/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift -frontend -c -primary-file /tmp/foo.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name foo -o /tmp/foo-0d117b.o 
1.  While emitting SIL for 'foo()' at /tmp/foo.swift:2:12
<unknown>:0: error: unable to execute command: Aborted
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)

for

$ ~/swift-source/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swiftc --version
Swift version 4.0-dev (LLVM 2c7b572db2, Clang 54c8e38855, Swift 51eac53c4a)
Target: x86_64-unknown-linux-gnu

@slavapestov
Copy link
Member

Yeah, I haven't fixed this yet.

@slavapestov
Copy link
Member

#25831

@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

4 participants