55// RUN: %check-interop-cxx-header-in-clang(%t/structs.h)
66
77public struct FirstSmallStruct {
8- public let x : UInt32
8+ public var x : UInt32
99#if CHANGE_LAYOUT
10- public let y : UInt32 = 0
10+ public var y : UInt32 = 0
1111#endif
1212
1313 public func dump( ) {
@@ -22,6 +22,12 @@ public struct FirstSmallStruct {
2222
2323// CHECK: class FirstSmallStruct final {
2424// CHECK-NEXT: public:
25+ // CHECK: inline FirstSmallStruct(const FirstSmallStruct &other) {
26+ // CHECK-NEXT: auto metadata = _impl::$s7Structs16FirstSmallStructVMa(0);
27+ // CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
28+ // CHECK-NEXT: _storage = swift::_impl::OpaqueStorage(vwTable);
29+ // CHECK-NEXT: vwTable->initializeWithCopy(_getOpaquePointer(), const_cast<char *>(other._getOpaquePointer()), metadata._0);
30+ // CHECK-NEXT: }
2531// CHECK: private:
2632// CHECK-NEXT: inline FirstSmallStruct(swift::_impl::ValueWitnessTable *vwTable) : _storage(vwTable) {}
2733// CHECK-NEXT: static inline FirstSmallStruct _make() {
@@ -57,6 +63,12 @@ public struct LargeStruct {
5763
5864// CHECK: class LargeStruct final {
5965// CHECK-NEXT: public:
66+ // CHECK: inline LargeStruct(const LargeStruct &other) {
67+ // CHECK-NEXT: auto metadata = _impl::$s7Structs11LargeStructVMa(0);
68+ // CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
69+ // CHECK-NEXT: _storage = swift::_impl::OpaqueStorage(vwTable);
70+ // CHECK-NEXT: vwTable->initializeWithCopy(_getOpaquePointer(), const_cast<char *>(other._getOpaquePointer()), metadata._0);
71+ // CHECK-NEXT: }
6072// CHECK: private:
6173// CHECK-NEXT: inline LargeStruct(swift::_impl::ValueWitnessTable *vwTable) : _storage(vwTable) {}
6274// CHECK-NEXT: static inline LargeStruct _make() {
@@ -124,6 +136,16 @@ public func createStructWithRefCountStoredProp() -> StructWithRefCountStoredProp
124136 return StructWithRefCountStoredProp ( x: 0 )
125137}
126138
139+ public func mutateSmall( _ x: inout FirstSmallStruct ) {
140+ #if CHANGE_LAYOUT
141+ let y = x. y
142+ x. y = x. x
143+ x. x = y
144+ #else
145+ x. x += 1
146+ #endif
147+ }
148+
127149// CHECK: inline LargeStruct createLargeStruct(swift::Int x) noexcept SWIFT_WARN_UNUSED_RESULT {
128150// CHECK-NEXT: return _impl::_impl_LargeStruct::returnNewValue([&](void * _Nonnull result) {
129151// CHECK-NEXT: _impl::$s7Structs17createLargeStructyAA0cD0VSiF(result, x);
@@ -136,6 +158,10 @@ public func createStructWithRefCountStoredProp() -> StructWithRefCountStoredProp
136158// CHECK-NEXT: });
137159// CHECK-NEXT: }
138160
161+ // CHECK: inline void mutateSmall(FirstSmallStruct& x) noexcept {
162+ // CHECK-NEXT: return _impl::$s7Structs11mutateSmallyyAA05FirstC6StructVzF(_impl::_impl_FirstSmallStruct::getOpaquePointer(x));
163+ // CHECK-NEXT: }
164+
139165// CHECK: inline void printSmallAndLarge(const FirstSmallStruct& x, const LargeStruct& y) noexcept {
140166// CHECK-NEXT: return _impl::$s7Structs18printSmallAndLargeyyAA05FirstC6StructV_AA0eG0VtF(_impl::_impl_FirstSmallStruct::getOpaquePointer(x), _impl::_impl_LargeStruct::getOpaquePointer(y));
141167// CHECK-NEXT: }
0 commit comments