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-14315] -emit-objc-header-path hits assertion on Linux #56674

Open
Lukasa opened this issue Mar 8, 2021 · 3 comments
Open

[SR-14315] -emit-objc-header-path hits assertion on Linux #56674

Lukasa opened this issue Mar 8, 2021 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@Lukasa
Copy link
Contributor

Lukasa commented Mar 8, 2021

Previous ID SR-14315
Radar rdar://problem/75178446
Original Reporter @Lukasa
Type Bug
Environment

Swift 5.3.3-RELEASE on Ubuntu 20.04

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

md5: 37147dd19c120d6292c0a4b518293fed

Issue Description:

Place the following content into a file called test.swift.

final class MyType {
    var count: Int = 55
}

@_cdecl("mytype_create")
public func mytype_create() -> OpaquePointer {
    let type = MyType()
    let retained = Unmanaged.passRetained(type).toOpaque()
    return OpaquePointer(retained)
}

@_cdecl("mytype_get_count")
public func mytype_create(_ type: OpaquePointer) -> CInt {
    let type = Unmanaged<MyType>.fromOpaque(UnsafeRawPointer(type)).takeUnretainedValue()
    return CInt(type.count)
}

Attempt to compile with swiftc -emit-objc-header-path test.h test.swift.

This triggers the following assertion:

swift: /home/buildnode/jenkins/workspace/oss-swift-5.3-package-linux-ubuntu-16_04/swift/lib/PrintAsObjC/ModuleContentsWriter.cpp:503: auto (anonymous namespace)::ModuleWriter::write()::(anonymous class)::operator()(swift::Decl *const *, swift::Decl *const *) const: Assertion `!(isa<ValueDecl>(*lhs) && isa<ValueDecl>(*rhs))' failed.
Stack dump:
0.  Program arguments: /usr/bin/swift -frontend -merge-modules -emit-module /tmp/test-e4af15.swiftmodule -parse-as-library -sil-merge-partial-modules -disable-diagnostic-passes -disable-sil-perf-optzns -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -emit-module-doc-path test.swiftdoc -emit-module-source-info-path test.swiftsourceinfo -emit-objc-header-path test.h -module-name test -o test.swiftmodule 
1.  Swift version 5.3.3 (swift-5.3.3-RELEASE)
2.  While generating Objective-C header
/usr/bin/swift[0x50aee34]
/usr/bin/swift[0x50ace00]
/usr/bin/swift[0x50af11a]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7fba52cfe390]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38)[0x7fba5142b438]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7fba5142d03a]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dbe7)[0x7fba51423be7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc92)[0x7fba51423c92]
/usr/bin/swift[0x699d40]
/lib/x86_64-linux-gnu/libc.so.6(+0x39242)[0x7fba5142f242]
/lib/x86_64-linux-gnu/libc.so.6(qsort_r+0x3cf)[0x7fba5142f6af]
/usr/bin/swift[0x6988a7]
/usr/bin/swift[0x69688f]
/usr/bin/swift[0x54450e]
/usr/bin/swift[0x1a9800b]
/usr/bin/swift[0x540036]
/usr/bin/swift[0x57e411]
/usr/bin/swift[0x587bcf]
/usr/bin/swift[0x57b322]
/usr/bin/swift[0x5780ef]
/usr/bin/swift[0x501c2c]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fba51416840]
/usr/bin/swift[0x5017a9]
<unknown>:0: error: unable to execute command: Aborted
<unknown>:0: error: merge-module command failed due to signal 6 (use -v to see invocation)
@Lukasa
Copy link
Contributor Author

Lukasa commented Mar 8, 2021

I believe this is caused by having declared a pair of functions that overload in Swift, but that have different `cdecl` qualifiers.

@stephentyrone
Copy link
Member

That sounds right. This reproduces on macOS, but goes away if I change the Swift name of the second function to anything else.

@typesanitizer
Copy link

@swift-ci create

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

No branches or pull requests

3 participants