mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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
This commit is contained in:
8
test/SIL/Serialization/Inputs/extern_with_nonnull.swift
Normal file
8
test/SIL/Serialization/Inputs/extern_with_nonnull.swift
Normal file
@@ -0,0 +1,8 @@
|
||||
@_extern(c, "takes_a_void_pointer")
|
||||
public func takes_a_void_pointer(_ pointer: UnsafeRawPointer)
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
public func callWithNonNull() {
|
||||
let pointer = UnsafeMutablePointer<Int>.allocate(capacity: 1)
|
||||
takes_a_void_pointer(UnsafeRawPointer(pointer))
|
||||
}
|
||||
7
test/SIL/Serialization/Inputs/extern_with_nullable.swift
Normal file
7
test/SIL/Serialization/Inputs/extern_with_nullable.swift
Normal file
@@ -0,0 +1,7 @@
|
||||
@_extern(c, "takes_a_void_pointer")
|
||||
public func takes_a_void_pointer(_ pointer: UnsafeRawPointer?)
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
public func callWithNullable() {
|
||||
takes_a_void_pointer(nil)
|
||||
}
|
||||
18
test/SIL/Serialization/extern_collision.swift
Normal file
18
test/SIL/Serialization/extern_collision.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-frontend -emit-module -enable-experimental-feature Extern -o %t %S/Inputs/extern_with_nullable.swift
|
||||
// RUN: %target-swift-frontend -emit-module -enable-experimental-feature Extern -o %t %S/Inputs/extern_with_nonnull.swift
|
||||
// RUN: %target-swift-frontend -emit-sil -o %t -I %t -primary-file %s -module-name main -O
|
||||
|
||||
// REQUIRES: swift_feature_Extern
|
||||
|
||||
// Don't crash or otherwise fail when inlining multiple functions that reference
|
||||
// @_extern(c) declarations of the same name but different types at the SIL
|
||||
// level.
|
||||
|
||||
import extern_with_nullable
|
||||
import extern_with_nonnull
|
||||
|
||||
public func main() {
|
||||
callWithNullable()
|
||||
callWithNonNull()
|
||||
}
|
||||
Reference in New Issue
Block a user