Skip to content

Commit b21485d

Browse files
committed
Only foreign thunks need to be serialized, not foreign definitions
This eliminates a SIL verification error with `@c` functions, which provide definitions for foreign entrypoints. We were serializing @c definitions when we shouldn't be, which would cause problems down the line if those @c definitions referenced something internal that they shouldn't.
1 parent 3cfcc90 commit b21485d

File tree

7 files changed

+38
-8
lines changed

7 files changed

+38
-8
lines changed

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,8 @@ SerializedKind_t SILDeclRef::getSerializedKind() const {
10251025
// @objc thunks for top-level functions are serializable since they're
10261026
// referenced from @convention(c) conversions inside inlinable
10271027
// functions.
1028-
return IsSerialized;
1028+
if (isThunk())
1029+
return IsSerialized;
10291030
}
10301031

10311032
// Declarations imported from Clang modules are serialized if

test/Interop/Cxx/extern-c/decls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ func zerome(ptr: UnsafeMutablePointer<Int>) {
66
}
77

88
// Verify that the asmname is "memset", not a C++-mangled version
9-
// CHECK: sil [serialized] [asmname "memset"] [clang memset] @$sSo6memsetySvSgAB_s5Int32VSitFTo : $@convention(c) (Optional<UnsafeMutableRawPointer>, Int32, Int) -> Optional<UnsafeMutableRawPointer>
9+
// CHECK: sil [asmname "memset"] [clang memset] @$sSo6memsetySvSgAB_s5Int32VSitFTo : $@convention(c) (Optional<UnsafeMutableRawPointer>, Int32, Int) -> Optional<UnsafeMutableRawPointer>

test/Interop/Cxx/foreign-reference/singleton-silgen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ public func test() {
3535

3636
// CHECK-LABEL: sil {{.*}}[asmname "{{.*}}test{{.*}}"] [clang DeletedSpecialMembers.test] @$sSo21DeletedSpecialMembersV4tests5Int32VyFTo : $@convention(cxx_method) (DeletedSpecialMembers) -> Int32
3737

38-
// CHECK-LABEL: sil [serialized] [asmname "{{.*}}mutate{{.*}}"] [clang mutateIt] @$sSo8mutateItyySo21DeletedSpecialMembersVFTo : $@convention(c) (DeletedSpecialMembers) -> ()
38+
// CHECK-LABEL: sil [asmname "{{.*}}mutate{{.*}}"] [clang mutateIt] @$sSo8mutateItyySo21DeletedSpecialMembersVFTo : $@convention(c) (DeletedSpecialMembers) -> ()

test/SILGen/cdecl-official.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func requiresThunk() {
3333
acceptSwiftFunc(orange)
3434
}
3535

36-
// CHECK-LABEL: sil [serialized] [asmname "cauliflower"] [ossa] @$s5cdecl8broccoliyS2iFTo : $@convention(c) (Int) -> Int {
36+
// CHECK-LABEL: sil [asmname "cauliflower"] [ossa] @$s5cdecl8broccoliyS2iFTo : $@convention(c) (Int) -> Int {
3737
// CHECK-NOT: apply
3838
// CHECK: return
3939
@c(cauliflower)

test/SILGen/extern_c.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func withCName(_ x: Int) -> Int
1010
@_extern(c, "take_c_func_ptr")
1111
func takeCFuncPtr(_ f: @convention(c) (Int) -> Int)
1212

13-
// CHECK-DAG: sil [serialized] [asmname "public_visible"] @$s8extern_c16publicVisibilityyS2iFTo : $@convention(c) (Int) -> Int
13+
// CHECK-DAG: sil [asmname "public_visible"] @$s8extern_c16publicVisibilityyS2iFTo : $@convention(c) (Int) -> Int
1414
@_extern(c, "public_visible")
1515
public func publicVisibility(_ x: Int) -> Int
1616

test/embedded/linkage/leaf_application.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
// Never referenced.
2727
// LIBRARY-IR-NOT: @"$es23_swiftEmptyArrayStorageSi_S3itvp" = linkonce_odr {{(protected |dllexport )?}}global
2828

29-
// Note: referenced by swift_allocEmptyBox.
30-
// LIBRARY-IR: @"$es16_emptyBoxStorageSi_Sitvp" = linkonce_odr {{(protected |dllexport )?}}global
31-
3229
// LIBRARY-IR-NOT: define {{.*}}@"$e7Library5helloSaySiGyF"()
3330
public func hello() -> [Int] {
3431
getArray()

test/embedded/serialization.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// Library module
5+
6+
// SIL checking
7+
// RUN: %target-swift-frontend %t/Library.swift -parse-as-library -entry-point-function-name Library_main -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -emit-sil -emit-module-path %t/Modules/Library.swiftmodule -o - | %FileCheck -check-prefix LIBRARY-SIL %s
8+
9+
// RUN: %target-swift-frontend %t/Application.swift -I %t/Modules -parse-as-library -entry-point-function-name Application_main -enable-experimental-feature Embedded -emit-sil -o - | %FileCheck -check-prefix APPLICATION-SIL %s
10+
11+
// REQUIRES: swift_in_compiler
12+
// REQUIRES: swift_feature_Embedded
13+
// REQUIRES: swift_feature_DeferredCodeGen
14+
15+
//--- Library.swift
16+
17+
func internalFunc() { }
18+
19+
// LIBRARY-SIL: sil [asmname "swift_dosomething"] @$e7Library17swift_dosomethingyyFTo : $@convention(c) () -> () {
20+
@c
21+
public func swift_dosomething() {
22+
internalFunc()
23+
}
24+
25+
//--- Application.swift
26+
import Library
27+
28+
// APPLICATION-SIL-LABEL: sil @$e11Application4testyyF : $@convention(thin) () -> ()
29+
public func test() {
30+
// CHECK: function_ref @$e7Library17swift_dosomethingyyFTo : $@convention(c) () -> ()
31+
swift_dosomething()
32+
}

0 commit comments

Comments
 (0)