mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
rdar://126954341 C types don't have separate size and stride, but in type layouts we always computed the size as if they did. This could cause wrong offsets in compact value witnesses
51 lines
3.0 KiB
Swift
51 lines
3.0 KiB
Swift
// RUN: %empty-directory(%t)
|
|
//
|
|
// RUN: %target-clang -fobjc-arc %S/Inputs/ObjCClasses/ObjCClasses.m -c -o %t/ObjCClasses.o
|
|
// RUN: %target-swift-frontend -I %S/Inputs/CTypes -prespecialize-generic-metadata -enable-experimental-feature LayoutStringValueWitnesses -enable-experimental-feature LayoutStringValueWitnessesInstantiation -enable-layout-string-value-witnesses -enable-layout-string-value-witnesses-instantiation -enable-type-layout -enable-autolinking-runtime-compatibility-bytecode-layouts -parse-stdlib -emit-module -emit-module-path=%t/layout_string_witnesses_types.swiftmodule %S/Inputs/layout_string_witnesses_types.swift
|
|
// RUN: %target-build-swift-dylib(%t/%target-library-name(layout_string_witnesses_types)) -I %S/Inputs/CTypes -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnessesInstantiation -Xfrontend -enable-layout-string-value-witnesses -Xfrontend -enable-layout-string-value-witnesses-instantiation -Xfrontend -enable-type-layout -Xfrontend -parse-stdlib -parse-as-library %S/Inputs/layout_string_witnesses_types.swift
|
|
// RUN: %target-codesign %t/%target-library-name(layout_string_witnesses_types)
|
|
// RUN: %target-build-swift -g -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnessesInstantiation -Xfrontend -enable-layout-string-value-witnesses -Xfrontend -enable-layout-string-value-witnesses-instantiation -Xfrontend -enable-type-layout -parse-stdlib -module-name layout_string_witnesses_dynamic -llayout_string_witnesses_types -L%t -I %S/Inputs/ObjCClasses/ %t/ObjCClasses.o -I %t -o %t/main %s %target-rpath(%t)
|
|
// RUN: %target-codesign %t/main
|
|
// RUN: %target-run %t/main %t/%target-library-name(layout_string_witnesses_types) | %FileCheck %s --check-prefix=CHECK
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: objc_interop
|
|
|
|
// Requires runtime functions added in Swift 5.9.
|
|
// UNSUPPORTED: use_os_stdlib
|
|
|
|
import Swift
|
|
import layout_string_witnesses_types
|
|
import ObjCClasses
|
|
import Foundation
|
|
|
|
func testNestedResilientObjc() {
|
|
let ptr = allocateInternalGenericPtr(of: NestedWrapper<ObjCPrintOnDealloc>.self)
|
|
|
|
do {
|
|
let x = NestedWrapper<ObjCPrintOnDealloc>(x: .init(x: ObjCPrintOnDealloc()), y: .init(x: ObjCPrintOnDealloc()))
|
|
testGenericInit(ptr, to: x)
|
|
}
|
|
|
|
do {
|
|
let y = NestedWrapper<ObjCPrintOnDealloc>(x: .init(x: ObjCPrintOnDealloc()), y: .init(x: ObjCPrintOnDealloc()))
|
|
// CHECK: Before deinit
|
|
print("Before deinit")
|
|
|
|
// CHECK-NEXT: ObjCPrintOnDealloc deinitialized!
|
|
// CHECK-NEXT: ObjCPrintOnDealloc deinitialized!
|
|
testGenericAssign(ptr, from: y)
|
|
}
|
|
|
|
// CHECK-NEXT: Before deinit
|
|
print("Before deinit")
|
|
|
|
// CHECK-NEXT: ObjCPrintOnDealloc deinitialized!
|
|
// CHECK-NEXT: ObjCPrintOnDealloc deinitialized!
|
|
testGenericDestroy(ptr, of: NestedWrapper<ObjCPrintOnDealloc>.self)
|
|
|
|
ptr.deallocate()
|
|
}
|
|
|
|
testNestedResilientObjc()
|