mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
`@_extern(c)` is meant for referencing C functions defined outside of this Swift file. Instead of using the C function name as the SIL function name, which is prone to collisions across different Swift modules, place make the C function name the "asmname" of the corresponding SIL function. Show that this prevents deserialization errors when there are conflicting Swift-level types for the same `@_extern(c)`-named symbol across modules. Part of rdar://137014448. Instead of using the C name as the mangled name of a SIL function
26 lines
795 B
Swift
26 lines
795 B
Swift
// RUN: %target-swift-emit-silgen %s -enable-experimental-feature Extern -verify
|
|
|
|
// REQUIRES: swift_feature_Extern
|
|
|
|
@_silgen_name("my_extern_func")
|
|
func my_extern_func1() // expected-note {{function declared here}}
|
|
|
|
@_silgen_name("my_extern_func")
|
|
func my_extern_func2(x: Int)
|
|
|
|
@_extern(c, "my_other_extern_func")
|
|
func my_other_extern_func1()
|
|
|
|
@_extern(c, "my_other_extern_func")
|
|
func my_other_extern_func2(x: Int)
|
|
|
|
public func foo() {
|
|
my_extern_func1()
|
|
my_extern_func2(x: 42) // expected-error {{function type mismatch, declared as '@convention(thin) () -> ()' but used as '@convention(thin) (Int) -> ()'}}
|
|
|
|
// @_extern(c, ...) keeps declarations separate at the SIL level, so we do
|
|
// not detect a mismatch here.
|
|
my_other_extern_func1()
|
|
my_other_extern_func2(x: 42)
|
|
}
|