Skip to content

Commit 4abba8c

Browse files
authored
Merge pull request #60448 from hyp/eng/resilient++
[interop][SwiftToCxx] ensure that resilient class values are supported
2 parents 03f2225 + 7ecf84a commit 4abba8c

File tree

7 files changed

+47
-1
lines changed

7 files changed

+47
-1
lines changed

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
347347
bool isIndirectReturnType =
348348
kind == FunctionSignatureKind::CFunctionProto &&
349349
!isKnownCType(resultTy, typeMapping) &&
350-
(isResilientType(resultTy) || isGenericType(resultTy) ||
350+
((isResilientType(resultTy) && !resultTy->isAnyClassReferenceType()) ||
351+
isGenericType(resultTy) ||
351352
interopContext.getIrABIDetails().shouldReturnIndirectly(resultTy));
352353
if (!isIndirectReturnType) {
353354
OptionalTypeKind retKind;

test/Interop/SwiftToCxx/class/swift-class-execution.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
// RUN: %target-codesign %t/swift-class-execution
99
// RUN: %target-run %t/swift-class-execution | %FileCheck %s
1010

11+
// RUN: %empty-directory(%t-evo)
12+
13+
// RUN: %target-swift-frontend %S/swift-class-in-cxx.swift -typecheck -module-name Class -clang-header-expose-public-decls -enable-library-evolution -emit-clang-header-path %t-evo/class.h
14+
15+
// RUN: %target-interop-build-clangxx -c %s -I %t-evo -o %t-evo/swift-class-execution.o
16+
// RUN: %target-interop-build-swift %S/swift-class-in-cxx.swift -o %t-evo/swift-class-execution-evo -Xlinker %t-evo/swift-class-execution.o -module-name Class -enable-library-evolution -Xfrontend -entry-point-function-name -Xfrontend swiftMain
17+
18+
// RUN: %target-codesign %t-evo/swift-class-execution-evo
19+
// RUN: %target-run %t-evo/swift-class-execution-evo | %FileCheck %s
20+
1121
// REQUIRES: executable_test
1222

1323
#include <assert.h>

test/Interop/SwiftToCxx/class/swift-class-in-cxx.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
// RUN: %check-interop-cxx-header-in-clang(%t/class.h)
66

7+
// RUN: %target-swift-frontend %s -typecheck -module-name Class -enable-library-evolution -clang-header-expose-public-decls -emit-clang-header-path %t/class-evo.h
8+
// RUN: %FileCheck %s < %t/class-evo.h
9+
10+
// RUN: %check-interop-cxx-header-in-clang(%t/class-evo.h)
11+
712
public final class ClassWithIntField {
813
var field: Int64
914

test/Interop/SwiftToCxx/class/swift-class-inheritance-execution.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
// RUN: not %target-interop-build-clangxx -c %s -I %t -o %t/swift-class-execution.o -DERROR1
1212
// RUN: not %target-interop-build-clangxx -c %s -I %t -o %t/swift-class-execution.o -DERROR2
1313

14+
// RUN: %empty-directory(%t-evo)
15+
16+
// RUN: %target-swift-frontend %S/swift-class-inheritance-in-cxx.swift -typecheck -module-name Class -enable-library-evolution -clang-header-expose-public-decls -emit-clang-header-path %t-evo/class.h
17+
18+
// RUN: %target-interop-build-clangxx -c %s -I %t-evo -o %t-evo/swift-class-execution.o
19+
// RUN: %target-interop-build-swift %S/swift-class-inheritance-in-cxx.swift -o %t-evo/swift-class-execution-evo -Xlinker %t-evo/swift-class-execution.o -module-name Class -enable-library-evolution -Xfrontend -entry-point-function-name -Xfrontend swiftMain
20+
21+
// RUN: %target-codesign %t-evo/swift-class-execution-evo
22+
// RUN: %target-run %t-evo/swift-class-execution-evo | %FileCheck %s
23+
1424
// REQUIRES: executable_test
1525

1626
#include <assert.h>

test/Interop/SwiftToCxx/class/swift-class-inheritance-in-cxx.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
// RUN: %check-interop-cxx-header-in-clang(%t/class.h)
66

7+
// RUN: %target-swift-frontend %s -typecheck -module-name Class -enable-library-evolution -clang-header-expose-public-decls -emit-clang-header-path %t/class-evo.h
8+
// RUN: %FileCheck %s < %t/class-evo.h
9+
10+
// RUN: %check-interop-cxx-header-in-clang(%t/class-evo.h)
11+
712
public class BaseClass {
813
var field: Int64
914

test/Interop/SwiftToCxx/structs/resilient-struct-in-cxx-execution.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ int main() {
4040
// CHECK: find - small dump
4141
// CURRENT-NEXT: x = 66
4242
// CHANGE-NEXT: x&y = 0&65
43+
copySmallStruct.mutate();
44+
copySmallStruct.dump();
45+
// CHECK: find - small dump
46+
// CURRENT-NEXT: x = 132
47+
// CHANGE-NEXT: x&y = 0&4294967230
4348

4449
printSmallAndLarge(smallStruct, largeStruct);
4550
// CHECK: find - small dump

test/Interop/SwiftToCxx/structs/resilient-struct-in-cxx.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ public struct FirstSmallStruct {
1616
print("x&y = \(x)&\(y)")
1717
#else
1818
print("x = \(x)")
19+
#endif
20+
}
21+
22+
public mutating func mutate() {
23+
x = x * 2
24+
#if CHANGE_LAYOUT
25+
y = ~y
1926
#endif
2027
}
2128
}
@@ -61,6 +68,9 @@ public struct FirstSmallStruct {
6168
// CHECK-NEXT: inline void FirstSmallStruct::dump() const {
6269
// CHECK-NEXT: return _impl::$s7Structs16FirstSmallStructV4dumpyyF(_getOpaquePointer());
6370
// CHECK-NEXT: }
71+
// CHECK-NEXT: inline void FirstSmallStruct::mutate() {
72+
// CHECK-NEXT: return _impl::$s7Structs16FirstSmallStructV6mutateyyF(_getOpaquePointer());
73+
// CHECK-NEXT: }
6474

6575
@frozen public struct FrozenStruct {
6676
private let storedInt: Int32

0 commit comments

Comments
 (0)