|
| 1 | +// Check that C functions are exported as needed. |
| 2 | + |
| 3 | +// REQUIRES: swift_in_compiler |
| 4 | +// REQUIRES: executable_test |
| 5 | +// REQUIRES: swift_feature_Embedded |
| 6 | +// REQUIRES: swift_feature_DeferredCodeGen |
| 7 | +// REQUIRES: swift_feature_CDecl |
| 8 | +// REQUIRES: swift_feature_CImplementation |
| 9 | +// REQUIRES: swift_feature_SymbolLinkageMarkers |
| 10 | + |
| 11 | +// RUN: %target-swift-frontend -emit-ir -o - %s -I %S/Inputs -package-name MyPackage -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -enable-experimental-feature CDecl -enable-experimental-feature CImplementation -enable-experimental-feature SymbolLinkageMarkers -parse-as-library | %FileCheck %s |
| 12 | + |
| 13 | +import MyModuleExports |
| 14 | + |
| 15 | +// --------------------------------------------------------------------------- |
| 16 | +// @c / @_cdecl on > internal declarations cause symbol emission |
| 17 | +// --------------------------------------------------------------------------- |
| 18 | + |
| 19 | +// CHECK: define {{(protected |dllexport )?}}void @lib_publicCDeclFunc() |
| 20 | +@_cdecl("lib_publicCDeclFunc") |
| 21 | +public func f1() { } |
| 22 | + |
| 23 | +// CHECK: define {{(protected |dllexport )?}}void @lib_publicCFunc() |
| 24 | +@c(lib_publicCFunc) |
| 25 | +package func f2() { } |
| 26 | + |
| 27 | +// CHECK: define hidden void @lib_publicCDeclFunc3 |
| 28 | +@_cdecl("lib_publicCDeclFunc3") |
| 29 | +internal func f3() { } |
| 30 | + |
| 31 | +// CHECK: define hidden void @lib_publicCDeclFunc4 |
| 32 | +@c("lib_publicCDeclFunc4") |
| 33 | +internal func f4() { } |
| 34 | + |
| 35 | +// CHECK-NOT: lib_publicCDeclFunc5 |
| 36 | +@_cdecl("lib_publicCDeclFunc5") |
| 37 | +private func f5() { } |
| 38 | + |
| 39 | +// CHECK-NOT: lib_publicCDeclFunc6 |
| 40 | +@c("lib_publicCDeclFunc6") |
| 41 | +private func f6() { } |
| 42 | + |
| 43 | +// --------------------------------------------------------------------------- |
| 44 | +// @implementation @c / @_cdecl cause symbol emission |
| 45 | +// --------------------------------------------------------------------------- |
| 46 | + |
| 47 | +// CHECK: define {{(protected |dllexport )?}}double @clib_func1 |
| 48 | +@_cdecl("clib_func1") @implementation |
| 49 | +public func clib_func1() -> Double { 0 } |
| 50 | + |
| 51 | +// CHECK: define {{(protected |dllexport )?}}double @clib_func2 |
| 52 | +@c @implementation |
| 53 | +package func clib_func2() -> Double { 0 } |
| 54 | + |
| 55 | +// CHECK: define hidden double @clib_func3 |
| 56 | +@_cdecl("clib_func3") @implementation |
| 57 | +internal func clib_func3() -> Double { 0 } |
| 58 | + |
| 59 | +// CHECK: define hidden double @clib_func4 |
| 60 | +@c @implementation |
| 61 | +internal func clib_func4() -> Double { 0 } |
| 62 | + |
| 63 | +// --------------------------------------------------------------------------- |
| 64 | +// @_section causes symbol emission |
| 65 | +// --------------------------------------------------------------------------- |
| 66 | + |
| 67 | +// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$e1c15symbolInSectionyyF" |
| 68 | +@_section("__TEXT,__mysection") |
| 69 | +public func symbolInSection() { } |
| 70 | + |
| 71 | +// CHECK: define hidden swiftcc void @"$e1c23internalSymbolInSectionyyF" |
| 72 | +@_section("__TEXT,__mysection") |
| 73 | +func internalSymbolInSection() { } |
| 74 | + |
| 75 | +// --------------------------------------------------------------------------- |
| 76 | +// @_used causes symbol emission |
| 77 | +// --------------------------------------------------------------------------- |
| 78 | + |
| 79 | +// CHECK: define hidden swiftcc void @"$e1c10usedSymbolyyF" |
| 80 | +@_used |
| 81 | +func usedSymbol() { } |
0 commit comments