Files
Patryk Stefanski fdd8185156 [cxx-interop] Lower @cxx @implementation functions to their C++ entry points
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
2026-09-02 07:40:15 -07:00

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 }