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-6135] Compiler crash on Linux when implicitly down casting inherited methods. #48690

Open
Lukasa opened this issue Oct 12, 2017 · 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 Linux Platform: Linux

Comments

@Lukasa
Copy link
Contributor

Lukasa commented Oct 12, 2017

Previous ID SR-6135
Radar None
Original Reporter @Lukasa
Type Bug
Environment
root@33c9c03465d6:/# lsb_release -d
Description: Ubuntu 14.04.5 LTS
root@33c9c03465d6:/# uname -a
Linux 33c9c03465d6 4.9.49-moby #​1 SMP Wed Sep 27 23:17:17 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
root@33c9c03465d6:/# swift --version
Swift version 4.0 (swift-4.0-RELEASE)
Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, Linux
Assignee @xedin
Priority Medium

md5: 95180e1bc917582e052d639920195ca9

Issue Description:

It's possible to trigger a compiler crash on Linux when implicitly down casting inherited methods. The following sample code triggers the crash:

class ParentTestCase {
    static var allParentTests: [(String, (ParentTestCase) -> () throws -> Void)] {
        return [("testNumberIsPositive", testNumberIsPositive)]
    }

    func testNumberIsPositive() throws {
        print(createNumber())
    }

    func createNumber() -> Int {
        return 1
    }
}

class ChildTestCase: ParentTestCase {
    static var allChildTests: [(String, (ChildTestCase) -> () throws -> Void)] {
        return [("testNumberIsGreaterThan1", testNumberIsGreaterThan1),
                ("testNumberIsPositive", testNumberIsPositive)]
    }

    func testNumberIsGreaterThan1() throws {
        print(createNumber())
    }

    override func createNumber() -> Int {
        return 2
    }
}

let x = ParentTestCase()
let y = ChildTestCase()

for (name, method) in ParentTestCase.allParentTests {
    print("Calling \(name)...")
    try method(x)()
}

for (name, method) in ChildTestCase.allChildTests {
    print("Calling \(name)...")
    try method(y)()
}

 

The expectation is that this code will compile and run, and indeed it does on Darwin. However, on Linux it triggers a compiler error and crashes the compiler with the following output:

subtype conversion in tuple and element is invalid: (ChildTestCase) -> () throws -> () to (ParentTestCase) -> () throws -> ()
0 swift 0x000000000376f838
1 swift 0x00000000037703d6
2 libpthread.so.0 0x00007fabb399b330
3 libc.so.6 0x00007fabb217dc37 gsignal + 55
4 libc.so.6 0x00007fabb2181028 abort + 328
5 swift 0x0000000001455061
6 swift 0x00000000014402b6
7 swift 0x000000000145dc96
8 swift 0x000000000145e772
9 swift 0x0000000001460ade
10 swift 0x000000000145ddc6
11 swift 0x000000000145c614
12 swift 0x000000000145c495
13 swift 0x000000000145af70
14 swift 0x000000000145a605
15 swift 0x000000000145b6c4
16 swift 0x000000000145a5f1
17 swift 0x000000000145a4c4
18 swift 0x00000000014decde
19 swift 0x000000000143e055
20 swift 0x0000000001315fbd
21 swift 0x0000000000f16de6
22 swift 0x00000000004a39a9
23 swift 0x00000000004a2775
24 swift 0x0000000000465a82
25 libc.so.6 0x00007fabb2168f45 __libc_start_main + 245
26 swift 0x000000000046365b
Stack dump:
0. Program arguments: /root/.swiftenv/versions/4.0/usr/bin/swift -frontend -c -primary-file test.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name test -o /tmp/test-dd9324.o
1. While walking into decl 'ChildTestCase' at test.swift:17:1
2. While walking into body of getter for allChildTests at test.swift:18:16

The error can be resolved by doing an explicit cast: that is, by changing line 18 from

("testNumberIsPositive", testNumberIsPositive)]

to

("testNumberIsPositive", testNumberIsPositive as (ChildTestCase) -> () throws -> Void)].
@belkadan
Copy link
Contributor

Hm, doesn't seem to be crashing for me on master. Maybe this has been fixed. @xedin, did anything change around function conversions recently?

@belkadan
Copy link
Contributor

(It does crash in the 4.0 release for me as well.)

@xedin
Copy link
Member

xedin commented Oct 13, 2017

@belkadan I don't recall any changes related to that, especially in 4.0.

@belkadan
Copy link
Contributor

Sorry, this would be a fix that didn't make it to 4.0.

@xedin
Copy link
Member

xedin commented Oct 13, 2017

Ah I misread... I thought that it doesn't crash on 4.0 🙂 If it doesn't crash on master that's most likely related to one of the changes I made to pick better bindings for subtypes, will investigate.

@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
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 Linux Platform: Linux
Projects
None yet
Development

No branches or pull requests

4 participants