Files
swift-mirror/test/Interop/Cxx/class/method/sret-win-arm64.swift
Hiroshi Yamauchi f815e1429e Ensure that BridgedTypeArray is indirectly returned
On Windows ARM64, how a struct value type is returned is sensitive to
conditions including whether a user-defined constructor exists,
etc. See

https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#return-values

That caused a calling convention mismatch between the
non-USED_IN_CPP_SOURCE (Swift) side and the USE_IN_CPP_SOURCE (C++)
side and a crash.

Add this constructor so that the calling convention matches.

This is a fix for the OnoneSimplification crash in

https://github.com/swiftlang/swift/issues/74866#issuecomment-2319618579

and is a partial fix for

https://github.com/swiftlang/swift/issues/74866#issuecomment-2319618579
2024-09-12 10:46:55 -07:00

32 lines
1.2 KiB
Swift

// RUN: %target-swift-emit-irgen -I %S/Inputs -cxx-interoperability-mode=default %s | %FileCheck %s -check-prefix=CHECK-before-fix
// RUN: %target-swift-emit-irgen -I %S/Inputs -cxx-interoperability-mode=default %s -Xcc -DAFTER_FIX | %FileCheck %s -check-prefix=CHECK-after-fix
// REQUIRES: OS=windows-msvc && CPU=aarch64
import SRetWinARM64
public struct OptionalTypeArray {
private let bridged: BridgedTypeArray
public init(bridged: BridgedTypeArray) {
self.bridged = bridged
}
}
public struct SubstitutionMap {
public let bridged: BridgedSubstitutionMap
public var replacementTypes: OptionalTypeArray {
let types = BridgedTypeArray.fromReplacementTypes(bridged)
return OptionalTypeArray(bridged: types)
}
}
public func test(sm: SubstitutionMap) -> OptionalTypeArray {
return sm.replacementTypes
}
// Check that BridgedTypeArray is indirectly returned via sret after the fix
// CHECK-before-fix: declare {{.*}} [2 x i64] @"?fromReplacementTypes@BridgedTypeArray@@SA?AU1@UBridgedSubstitutionMap@@@Z"(i64)
// CHECK-after-fix: declare {{.*}} void @"?fromReplacementTypes@BridgedTypeArray@@SA?AU1@UBridgedSubstitutionMap@@@Z"(ptr inreg sret(%struct.BridgedTypeArray) align 8, i64)