mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Extend @_extern to global and static variables
Allow external declaration of global variables via `@_extern(c)`. Such variables need to have types represented in C (of course), have only storage (no accessors), and cannot have initializers. At the SIL level, we use the SIL asmname attribute to get the appropriate C name. While here, slightly shore up the `@_extern(c)` checking, which should fix issue #70776 / rdar://153515764.
This commit is contained in:
@@ -2,6 +2,17 @@
|
||||
|
||||
// REQUIRES: swift_feature_Extern
|
||||
|
||||
|
||||
// CHECK: @pointer_c = external global
|
||||
@_extern(c)
|
||||
var pointer_c: UnsafeMutablePointer<Int>
|
||||
|
||||
// CHECK: @nullable_pointer_c = external global
|
||||
@_extern(c)
|
||||
var nullable_pointer_c: UnsafeMutablePointer<Int>?
|
||||
|
||||
func acceptInt(_: Int) { }
|
||||
|
||||
func test() {
|
||||
// CHECK: call void @explicit_extern_c()
|
||||
explicit_extern_c()
|
||||
@@ -12,6 +23,11 @@ func test() {
|
||||
default_arg_value()
|
||||
// CHECK: call void @default_arg_value(i32 24)
|
||||
default_arg_value(24)
|
||||
|
||||
// CHECK: call void @swift_beginAccess(ptr @pointer_c
|
||||
// CHECK-NEXT: [[POINTEE_VAL:%[0-9]+]] = load ptr, ptr @pointer_c
|
||||
// CHECK-NEXT: call void @swift_endAccess
|
||||
acceptInt(pointer_c.pointee)
|
||||
}
|
||||
|
||||
test()
|
||||
|
||||
Reference in New Issue
Block a user