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-8469] Crash on invalid Swift function #50990

Closed
macdrevx opened this issue Aug 6, 2018 · 5 comments
Closed

[SR-8469] Crash on invalid Swift function #50990

macdrevx opened this issue Aug 6, 2018 · 5 comments
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

@macdrevx
Copy link

macdrevx commented Aug 6, 2018

Previous ID SR-8469
Radar rdar://problem/43888895
Original Reporter @macdrevx
Type Bug
Status Resolved
Resolution Done
Environment

$ swiftc --version

Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)

Target: x86_64-apple-darwin17.7.0

Xcode Version 9.4.1 (9F2000)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @slavapestov
Priority Medium

md5: ce03de672a4ef4fa279c9c44183686f9

Issue Description:

Steps to reproduce:

1. Compile the following:

final class Baz {}


final class Bar {
    private let x: Baz
    init(x: Baz) {
        self.x = x
    }
}


final class Foo {
    private var bar: Bar?


    private func navigate(with baz: Baz?) {
        bar = nil
        guard let baz = baz else { return }
        let bar = Bar(x: baz)
        self.bar = bar
    }
}

Expected result:

Something along the lines of: "error: use of local variable 'bar' before its declaration"

Actual result:

The compiler crashes:

$ swiftc ~/Desktop/SilgenCrash/SilgenCrash/main.swift 
0  swift                    0x0000000103b8dfea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000103b8d3a6 SignalHandler(int) + 966
2  libsystem_platform.dylib 0x00007fff55047f5a _sigtramp + 26
3  libsystem_platform.dylib 000000000000000000 _sigtramp + 2868609216
4  swift                    0x0000000100b78ca2 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6578
5  swift                    0x0000000100b350fb swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 379
6  swift                    0x0000000100a9d2f5 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 565
7  swift                    0x0000000100a9c6e5 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 741
8  swift                    0x0000000100b85e23 (anonymous namespace)::SILGenType::emitType() + 819
9  swift                    0x0000000100aa65d6 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 70
10 swift                    0x0000000100aa570b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1371
11 swift                    0x0000000100aa72f1 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) + 865
12 swift                    0x00000001001eb85c performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 27340
13 swift                    0x00000001001e3304 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7908
14 swift                    0x0000000100197ce5 main + 18917
15 libdyld.dylib            0x00007fff54d39015 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/andrew/Desktop/SilgenCrash/SilgenCrash/main.swift -target x86_64-apple-darwin17.7.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name main -o /var/folders/5y/fb3xqbqn0510r90hhjllcy3m0000gn/T/main-b00059.o 
1.  While emitting SIL for 'navigate(with:)' at /Users/andrew/Desktop/SilgenCrash/SilgenCrash/main.swift:13:13
2.  While silgen emitFunction SIL function "@_T04main3FooC8navigate029_12232F587A4C5CD8B1EEDF696793E2FCLLyAA3BazCSg4with_tF".
 for 'navigate(with:)' at /Users/andrew/Desktop/SilgenCrash/SilgenCrash/main.swift:13:13
<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)

Discussion:

This code is invalid because the first line of navigate(with:) refers to bar instead of self.bar

@macdrevx
Copy link
Author

macdrevx commented Aug 7, 2018

I'm told that this works as expected in Xcode 10 beta 3.

@belkadan
Copy link
Contributor

It's not printing an error for me on master, so something is still wrong.

@swift-ci create

@jckarter
Copy link
Member

Wouldn't that be behaving correctly not to error? Before the local `bar` is declared, `bar` refers to the outer scope's `bar`. Maybe worth warning about at least, but this seems valid.

@belkadan
Copy link
Contributor

Oh, I had forgotten that we made that change. It used to say "use of 'bar' before it's declared" even with the one in the outer scope. Okay.

@slavapestov
Copy link
Member

No longer crashes in 5.2 beta 1.

@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

5 participants