Skip to content

Commit ba149d9

Browse files
authored
Merge pull request #41462 from zoecarver/add-all-witness-table-copy-and-assign
2 parents f4d56d3 + 8ac98f6 commit ba149d9

File tree

5 files changed

+109
-6
lines changed

5 files changed

+109
-6
lines changed

lib/IRGen/GenStruct.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,52 @@ namespace {
734734
isOutlined);
735735
}
736736

737+
void assignWithCopy(IRGenFunction &IGF, Address destAddr, Address srcAddr,
738+
SILType T, bool isOutlined) const override {
739+
if (auto copyConstructor = findCopyConstructor()) {
740+
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
741+
srcAddr.getAddress(),
742+
destAddr.getAddress());
743+
return;
744+
}
745+
StructTypeInfoBase<AddressOnlyClangRecordTypeInfo, FixedTypeInfo,
746+
ClangFieldInfo>::assignWithCopy(IGF, destAddr,
747+
srcAddr, T,
748+
isOutlined);
749+
}
750+
751+
void initializeWithTake(IRGenFunction &IGF, Address dest, Address src,
752+
SILType T, bool isOutlined) const override {
753+
if (auto copyConstructor = findCopyConstructor()) {
754+
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
755+
src.getAddress(),
756+
dest.getAddress());
757+
destroy(IGF, src, T, isOutlined);
758+
return;
759+
}
760+
761+
StructTypeInfoBase<AddressOnlyClangRecordTypeInfo, FixedTypeInfo,
762+
ClangFieldInfo>::initializeWithTake(IGF, dest,
763+
src, T,
764+
isOutlined);
765+
}
766+
767+
void assignWithTake(IRGenFunction &IGF, Address dest, Address src, SILType T,
768+
bool isOutlined) const override {
769+
if (auto copyConstructor = findCopyConstructor()) {
770+
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
771+
src.getAddress(),
772+
dest.getAddress());
773+
destroy(IGF, src, T, isOutlined);
774+
return;
775+
}
776+
777+
StructTypeInfoBase<AddressOnlyClangRecordTypeInfo, FixedTypeInfo,
778+
ClangFieldInfo>::assignWithTake(IGF, dest,
779+
src, T,
780+
isOutlined);
781+
}
782+
737783
llvm::NoneType getNonFixedOffsets(IRGenFunction &IGF) const { return None; }
738784
llvm::NoneType getNonFixedOffsets(IRGenFunction &IGF, SILType T) const {
739785
return None;

test/Interop/Cxx/class/constructors-irgen.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ public func createStructWithSubobjectCopyConstructorAndValue() {
6161
// ITANIUM_X64: [[TMP_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[TMP]] to %struct.StructWithCopyConstructorAndValue*
6262
// ITANIUM_X64: [[MEMBER_AS_STRUCT_2:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
6363
// ITANIUM_X64: call void @_ZN33StructWithCopyConstructorAndValueC1ERKS_(%struct.StructWithCopyConstructorAndValue* [[TMP_STRUCT]], %struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT_2]])
64-
// ITANIUM_X64: [[OBJ_MEMBER:%.*]] = getelementptr inbounds %TSo42StructWithSubobjectCopyConstructorAndValueV, %TSo42StructWithSubobjectCopyConstructorAndValueV* [[OBJ]], i32 0, i32 0
65-
// ITANIUM_X64: call %TSo33StructWithCopyConstructorAndValueV* @"$sSo33StructWithCopyConstructorAndValueVWOb"(%TSo33StructWithCopyConstructorAndValueV* [[TMP]], %TSo33StructWithCopyConstructorAndValueV* [[OBJ_MEMBER]])
6664
// ITANIUM_X64: ret void
6765

6866
// ITANIUM_ARM-LABEL: define protected swiftcc void @"$ss48createStructWithSubobjectCopyConstructorAndValueyyF"()
@@ -74,8 +72,6 @@ public func createStructWithSubobjectCopyConstructorAndValue() {
7472
// ITANIUM_ARM: [[TMP_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[TMP]] to %struct.StructWithCopyConstructorAndValue*
7573
// ITANIUM_ARM: [[MEMBER_AS_STRUCT_2:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
7674
// ITANIUM_ARM: call %struct.StructWithCopyConstructorAndValue* @_ZN33StructWithCopyConstructorAndValueC2ERKS_(%struct.StructWithCopyConstructorAndValue* [[TMP_STRUCT]], %struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT_2]])
77-
// ITANIUM_ARM: [[OBJ_MEMBER:%.*]] = getelementptr inbounds %TSo42StructWithSubobjectCopyConstructorAndValueV, %TSo42StructWithSubobjectCopyConstructorAndValueV* [[OBJ]], i32 0, i32 0
78-
// ITANIUM_ARM: call %TSo33StructWithCopyConstructorAndValueV* @"$sSo33StructWithCopyConstructorAndValueVWOb"(%TSo33StructWithCopyConstructorAndValueV* [[TMP]], %TSo33StructWithCopyConstructorAndValueV* [[OBJ_MEMBER]])
7975
// ITANIUM_ARM: ret void
8076

8177
// MICROSOFT_X64-LABEL: define dllexport swiftcc void @"$ss48createStructWithSubobjectCopyConstructorAndValueyyF"()
@@ -87,8 +83,6 @@ public func createStructWithSubobjectCopyConstructorAndValue() {
8783
// MICROSOFT_X64: [[TMP_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[TMP]] to %struct.StructWithCopyConstructorAndValue*
8884
// MICROSOFT_X64: [[MEMBER_AS_STRUCT_2:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
8985
// MICROSOFT_X64: call %struct.StructWithCopyConstructorAndValue* @"??0StructWithCopyConstructorAndValue@@QEAA@AEBU0@@Z"(%struct.StructWithCopyConstructorAndValue* [[TMP_STRUCT]], %struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT_2]])
90-
// MICROSOFT_X64: [[OBJ_MEMBER:%.*]] = getelementptr inbounds %TSo42StructWithSubobjectCopyConstructorAndValueV, %TSo42StructWithSubobjectCopyConstructorAndValueV* [[OBJ]], i32 0, i32 0
91-
// MICROSOFT_X64: call %TSo33StructWithCopyConstructorAndValueV* @"$sSo33StructWithCopyConstructorAndValueVWOb"(%TSo33StructWithCopyConstructorAndValueV* [[TMP]], %TSo33StructWithCopyConstructorAndValueV* [[OBJ_MEMBER]])
9286
// MICROSOFT_X64: ret void
9387
let member = StructWithCopyConstructorAndValue()
9488
let obj = StructWithSubobjectCopyConstructorAndValue(member: member)

test/Interop/Cxx/value-witness-table/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ module ClassTemplateMetadata {
1717
header "class-template-metadata.h"
1818
requires cplusplus
1919
}
20+
21+
module WitnessLifetimeOperations {
22+
header "witness-lifetime-operations.h"
23+
requires cplusplus
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef TEST_INTEROP_CXX_VALUE_WITNESS_TABLE_INPUTS_WITNESS_LIFETIME_OPERATIONS_H
2+
#define TEST_INTEROP_CXX_VALUE_WITNESS_TABLE_INPUTS_WITNESS_LIFETIME_OPERATIONS_H
3+
4+
struct NonTrivial {
5+
NonTrivial() { }
6+
NonTrivial(const NonTrivial& other) { }
7+
~NonTrivial() { }
8+
};
9+
10+
#endif // TEST_INTEROP_CXX_VALUE_WITNESS_TABLE_INPUTS_WITNESS_LIFETIME_OPERATIONS_H
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %target-swift-frontend -enable-cxx-interop -I %S/Inputs %s -emit-ir | %FileCheck %s
2+
3+
import WitnessLifetimeOperations
4+
5+
struct Holder<T> {
6+
var holding: T
7+
}
8+
9+
let h = Holder(holding: NonTrivial())
10+
11+
// $sSo10NonTrivialVwxx ---> destroy value witness for __C.NonTrivial
12+
// CHECK-LABEL: define linkonce_odr hidden void @"$sSo10NonTrivialVwxx"
13+
// CHECK-NOT: call
14+
// CHECK: call void @{{_ZN10NonTrivialD(1|2)Ev|"\?\?1NonTrivial@@QEAA@XZ"}}(%struct.NonTrivial* %{{[0-9]+}})
15+
// CHECK-NOT: call
16+
// CHECK: ret void
17+
18+
// $sSo10NonTrivialVwcp ---> initializeWithCopy value witness for __C.NonTrivial
19+
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @"$sSo10NonTrivialVwcp"
20+
// CHECK-NOT: call
21+
// CHECK: call {{void|\%struct\.NonTrivial\*}} @{{_ZN10NonTrivialC(1|2)ERKS_|"\?\?0NonTrivial@@QEAA@AEBU0@@Z"}}(%struct.NonTrivial* %{{[0-9]+}}, %struct.NonTrivial* %{{[0-9]+}})
22+
// CHECK-NOT: call
23+
// CHECK: ret %swift.opaque*
24+
25+
// $sSo10NonTrivialVwca ---> assignWithCopy value witness for __C.NonTrivia
26+
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @"$sSo10NonTrivialVwca"
27+
// CHECK-NOT: call
28+
// CHECK: call {{void|\%struct\.NonTrivial\*}} @{{_ZN10NonTrivialC(1|2)ERKS_|"\?\?0NonTrivial@@QEAA@AEBU0@@Z"}}(%struct.NonTrivial* %{{[0-9]+}}, %struct.NonTrivial* %{{[0-9]+}})
29+
// CHECK-NOT: call
30+
// CHECK: ret %swift.opaque*
31+
32+
// $sSo10NonTrivialVwtk ---> initializeWithTake value witness for __C.NonTrivial
33+
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @"$sSo10NonTrivialVwtk"
34+
// CHECK-NOT: call
35+
// CHECK: call {{void|\%struct\.NonTrivial\*}} @{{_ZN10NonTrivialC(1|2)ERKS_|"\?\?0NonTrivial@@QEAA@AEBU0@@Z"}}(%struct.NonTrivial* %{{[0-9]+}}, %struct.NonTrivial* %{{[0-9]+}})
36+
// CHECK-NOT: call
37+
// CHECK: call void @{{_ZN10NonTrivialD(1|2)Ev|"\?\?1NonTrivial@@QEAA@XZ"}}(%struct.NonTrivial* %{{[0-9]+}})
38+
// CHECK-NOT: call
39+
// CHECK: ret %swift.opaque*
40+
41+
// $sSo10NonTrivialVwta ---> assignWithTake value witness for __C.NonTrivial
42+
// CHECK-LABEL: define linkonce_odr hidden %swift.opaque* @"$sSo10NonTrivialVwta"
43+
// CHECK-NOT: call
44+
// CHECK: call {{void|\%struct\.NonTrivial\*}} @{{_ZN10NonTrivialC(1|2)ERKS_|"\?\?0NonTrivial@@QEAA@AEBU0@@Z"}}(%struct.NonTrivial* %{{[0-9]+}}, %struct.NonTrivial* %{{[0-9]+}})
45+
// CHECK-NOT: call
46+
// CHECK: call void @{{_ZN10NonTrivialD(1|2)Ev|"\?\?1NonTrivial@@QEAA@XZ"}}(%struct.NonTrivial* %{{[0-9]+}})
47+
// CHECK-NOT: call
48+
// CHECK: ret %swift.opaque*

0 commit comments

Comments
 (0)