mirror of
https://github.com/apple/swift.git
synced 2026-10-16 16:50:49 +02:00
Emit a matched `@cxx @implementation` function's body under the matched C++ declaration's mangled symbol so C++ callers link against the Swift definition directly. A @cxx function's only callers are in C++, which the SIL optimizer cannot see; mark it as having foreign references so dead-function elimination does not delete a non-public implementation, and suppress the native Swift entry point. rdar://185906680
36 lines
1.1 KiB
Swift
36 lines
1.1 KiB
Swift
// The @cxx attribute (and the @implementation match it drives) must survive
|
|
// serialization: compiling from a .sib must produce the same C++ entry point
|
|
// as compiling from source.
|
|
|
|
// RUN: %empty-directory(%t)
|
|
|
|
// Ensure .swift -> .ll
|
|
// RUN: %target-swift-frontend \
|
|
// RUN: -cxx-interoperability-mode=default \
|
|
// RUN: -enable-experimental-feature CxxImplementation \
|
|
// RUN: -I %S/Inputs/cxx-attr \
|
|
// RUN: -emit-ir %s | %FileCheck %s
|
|
|
|
// Ensure .swift -> .sib -> .ll
|
|
// RUN: %target-swift-frontend \
|
|
// RUN: -cxx-interoperability-mode=default \
|
|
// RUN: -enable-experimental-feature CxxImplementation \
|
|
// RUN: -I %S/Inputs/cxx-attr \
|
|
// RUN: -emit-sib %s -o %t/cxx_attr.sib
|
|
// RUN: %target-swift-frontend \
|
|
// RUN: -cxx-interoperability-mode=default \
|
|
// RUN: -enable-experimental-feature CxxImplementation \
|
|
// RUN: -I %S/Inputs/cxx-attr \
|
|
// RUN: -emit-sil %t/cxx_attr.sib | %FileCheck --check-prefix=SIL %s
|
|
|
|
// REQUIRES: swift_feature_CxxImplementation
|
|
|
|
import CxxAttr
|
|
|
|
// CHECK: define {{.*}}@{{_Z3fooi|"\?foo@@YAHH@Z"}}
|
|
|
|
// SIL: [asmname "{{_Z3fooi|\?foo@@YAHH@Z}}"]
|
|
|
|
@cxx @implementation
|
|
func foo(_ x: Int32) -> Int32 { return x }
|