Files
swift-mirror/test/embedded/linkage/weak_linkage_bug.swift
Doug Gregor bb1f2e271f [Embedded tests] Add %embedded-stdlib and update %target-embedded-{link,posix-shim}
Define new lit substitutions for embedded test link lines:

  %embedded-stdlib            full path to libswiftCore.a
  %target-embedded-posix-shim now includes libswiftCore.a (and
                              libswiftEmbeddedPlatformPOSIX.a when needed)
  %target-embedded-link       wraps %target-clang together with the
                              embedded stdlib and POSIX shim

The archive is empty under the default code-generation model, so including
it unconditionally is harmless; the substitutions take effect cleanly when
the archive carries real code under future code-generation modes.

Update the seven embedded executable tests that need the stdlib archive on
their link line (or that were composing the link by hand) to use the new
substitutions.
2026-07-13 23:27:17 -07:00

70 lines
2.0 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -c -wmo -emit-module -o %t/C.o %t/C.swift -enable-experimental-feature Embedded -parse-as-library
// RUN: %target-swift-frontend -num-threads 1 -c -I %t -emit-module -o %t/D.o -o %t/D2.o %t/D.swift %t/D2.swift -wmo -enable-experimental-feature Embedded -parse-as-library
// RUN: %target-embedded-link %target-clang-resource-dir-opt %t/C.o %t/D.o %t/D2.o -o %t/Application
// RUN: %target-run %t/Application | %FileCheck %s
// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -emit-ir -wmo -emit-module -o %t/C.ll %t/C.swift -enable-experimental-feature Embedded -parse-as-library -enable-experimental-feature CoroutineAccessors
// RUN: %target-swift-frontend -num-threads 1 -emit-ir -I %t -emit-module -o %t/D.ll -o %t/D2.ll %t/D.swift %t/D2.swift -wmo -enable-experimental-feature Embedded -parse-as-library -enable-experimental-feature CoroutineAccessors
// RUN: %FileCheck %s --check-prefix=VTABLE-C < %t/C.ll
// RUN: %FileCheck %s --check-prefix=VTABLE-D < %t/D.ll
// REQUIRES: executable_test
// REQUIRES: swift_feature_Embedded
// REQUIRES: swift_feature_CoroutineAccessors
// CHECK: MyClass.foo
// Make sure the vtable layouts match.
// VTABLE-C: @"$e1C7MyClassCySiGMf" = linkonce_odr hidden constant <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>
// VTABLE-D: @"$e1C7MyClassCySiGMf" = linkonce_odr hidden constant <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>
//--- C.swift
public class BaseClass {}
public class MyClass<T>: BaseClass {
var _t : T
public init(_ t: T) { self._t = t }
public func foo() { print("MyClass.foo") }
}
public func foo() {
let o = MyClass(1)
o.foo()
}
//--- D.swift
import C
public func bar() -> MyClass<Int>{
let o = MyClass(5)
return o
}
@main
struct Main {
static func main() {
bar()
test()
}
}
//--- D2.swift
import C
public func test() -> MyClass<Int> {
let r = bar()
r.foo()
return r
}