Files
swift-mirror/test/SILGen/silgen_name_conflict.swift
Doug Gregor 4b745170c3 [SILGen] Map the @_extern(c) C function name over to the asmname of a SIL function
`@_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
2025-10-15 23:19:12 -07:00

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)
}