Skip to content

Commit 6f5cb90

Browse files
authored
Merge pull request #68478 from hyp/eng/5.10/109417079
[interop] do not synthesize special members for C++ records with inco…
2 parents 5b1d62b + d316825 commit 6f5cb90

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,26 @@ ImportedType findOptionSetType(clang::QualType type,
841841
return importedType;
842842
}
843843

844+
static bool areRecordFieldsComplete(const clang::CXXRecordDecl *decl) {
845+
for (const auto *f : decl->fields()) {
846+
auto *fieldRecord = f->getType()->getAsCXXRecordDecl();
847+
if (fieldRecord) {
848+
if (!fieldRecord->isCompleteDefinition()) {
849+
return false;
850+
}
851+
if (!areRecordFieldsComplete(fieldRecord))
852+
return false;
853+
}
854+
}
855+
for (const auto base : decl->bases()) {
856+
if (auto *baseRecord = base.getType()->getAsCXXRecordDecl()) {
857+
if (!areRecordFieldsComplete(baseRecord))
858+
return false;
859+
}
860+
}
861+
return true;
862+
}
863+
844864
namespace {
845865
/// Customized llvm::DenseMapInfo for storing borrowed APSInts.
846866
struct APSIntRefDenseMapInfo {
@@ -2663,10 +2683,11 @@ namespace {
26632683
auto &clangSema = Impl.getClangSema();
26642684
// Make Clang define any implicit constructors it may need (copy,
26652685
// default). Make sure we only do this if the class has been fully defined
2666-
// and we're not in a dependent context (this is equivalent to the logic
2667-
// in CanDeclareSpecialMemberFunction in Clang's SemaLookup.cpp).
2668-
// TODO: I suspect this if-statement does not need to be here.
2669-
if (!decl->isBeingDefined() && !decl->isDependentContext()) {
2686+
// with complete fields, and we're not in a dependent context(this is
2687+
// equivalent to the logic in CanDeclareSpecialMemberFunction in Clang's
2688+
// SemaLookup.cpp).
2689+
if (!decl->isBeingDefined() && !decl->isDependentContext() &&
2690+
areRecordFieldsComplete(decl)) {
26702691
if (decl->needsImplicitDefaultConstructor()) {
26712692
clang::CXXConstructorDecl *ctor =
26722693
clangSema.DeclareImplicitDefaultConstructor(

test/Interop/Cxx/foreign-reference/nullable-module-interface.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// CHECK: func mutateIt(_: Empty)
1010

1111
// CHECK: class IntPair {
12-
// CHECK: var a: Int32
13-
// CHECK: var b: Int32
1412
// CHECK: func test() -> Int32
1513
// CHECK: class func create() -> IntPair!
14+
// CHECK: var a: Int32
15+
// CHECK: var b: Int32
1616
// CHECK: }
1717
// CHECK: func mutateIt(_ x: IntPair!)

test/Interop/Cxx/foreign-reference/pod-module-interface.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,60 +20,60 @@
2020

2121
// CHECK: class IntPair {
2222
// CHECK-NOT: init
23-
// CHECK: var a: Int32
24-
// CHECK: var b: Int32
2523
// CHECK: func test() -> Int32
2624
// CHECK: func testMutable() -> Int32
2725
// CHECK: class func create() -> IntPair
26+
// CHECK: var a: Int32
27+
// CHECK: var b: Int32
2828
// CHECK: }
2929
// CHECK: func mutateIt(_ x: IntPair)
3030
// CHECK-NOT: func passThroughByValue(_ x: IntPair) -> IntPair
3131

3232
// CHECK: class RefHoldingPair {
3333
// CHECK-NOT: init
3434
// CHECK-NOT: pair
35-
// CHECK: var otherValue: Int32
3635
// CHECK: func test() -> Int32
3736
// CHECK: func testMutable() -> Int32
3837
// CHECK: class func create() -> RefHoldingPair
38+
// CHECK: var otherValue: Int32
3939
// CHECK: }
4040

4141
// CHECK: class RefHoldingPairRef {
4242
// CHECK-NOT: init
43-
// CHECK: var pair: IntPair
44-
// CHECK: var otherValue: Int32
4543
// CHECK: func test() -> Int32
4644
// CHECK: func testMutable() -> Int32
4745
// CHECK: class func create() -> RefHoldingPairRef
46+
// CHECK: var pair: IntPair
47+
// CHECK: var otherValue: Int32
4848
// CHECK: }
4949

5050
// CHECK: class RefHoldingPairPtr {
5151
// CHECK-NOT: init
52-
// CHECK: var pair: IntPair
53-
// CHECK: var otherValue: Int32
5452
// CHECK: func test() -> Int32
5553
// CHECK: func testMutable() -> Int32
5654
// CHECK: class func create() -> RefHoldingPairPtr
55+
// CHECK: var pair: IntPair
56+
// CHECK: var otherValue: Int32
5757
// CHECK: }
5858

5959
// CHECK: struct ValueHoldingPair {
6060
// CHECK-NOT: init
6161
// CHECK-NOT: pair
6262
// CHECK: init()
63-
// CHECK: var otherValue: Int32
6463
// CHECK: func test() -> Int32
6564
// CHECK: mutating func testMutable() -> Int32
6665
// CHECK: static func create() -> UnsafeMutablePointer<ValueHoldingPair>
66+
// CHECK: var otherValue: Int32
6767
// CHECK: }
6868

6969
// CHECK: class BigType {
7070
// CHECK-NOT: init
71-
// CHECK: var a: Int32
72-
// CHECK: var b: Int32
73-
// CHECK: var buffer:
7471
// CHECK: func test() -> Int32
7572
// CHECK: func testMutable() -> Int32
7673
// CHECK: class func create() -> BigType
74+
// CHECK: var a: Int32
75+
// CHECK: var b: Int32
76+
// CHECK: var buffer:
7777
// CHECK: }
7878
// CHECK: func mutateIt(_ x: BigType)
7979
// CHECK-NOT: func passThroughByValue(_ x: BigType) -> BigType

test/Interop/Cxx/foreign-reference/singleton-module-interface.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@
44

55
// CHECK: class DeletedDtor {
66
// CHECK-NOT: init
7-
// CHECK: var value: Int32
87
// CHECK: func test() -> Int32
98
// CHECK: func testMutable() -> Int32
109
// CHECK: class func create() -> DeletedDtor
10+
// CHECK: var value: Int32
1111
// CHECK: }
1212
// CHECK: func mutateIt(_ x: DeletedDtor)
1313

1414
// CHECK: class PrivateDtor {
1515
// CHECK-NOT: init
16-
// CHECK: var value: Int32
1716
// CHECK: func test() -> Int32
1817
// CHECK: func testMutable() -> Int32
1918
// CHECK: class func create() -> PrivateDtor
19+
// CHECK: var value: Int32
2020
// CHECK: }
2121
// CHECK: func mutateIt(_ x: PrivateDtor)
2222

2323
// CHECK: class DeletedSpecialMembers {
2424
// CHECK-NOT: init
25-
// CHECK: var value: Int32
2625
// CHECK: func test() -> Int32
2726
// CHECK: func testMutable() -> Int32
2827
// CHECK: class func create() -> DeletedSpecialMembers
28+
// CHECK: var value: Int32
2929
// CHECK: }
3030
// CHECK: func mutateIt(_ x: DeletedSpecialMembers)
3131

3232
// CHECK: class PrivateSpecialMembers {
3333
// CHECK-NOT: init
34-
// CHECK: var value: Int32
3534
// CHECK: func test() -> Int32
3635
// CHECK: func testMutable() -> Int32
3736
// CHECK: class func create() -> PrivateSpecialMembers
37+
// CHECK: var value: Int32
3838
// CHECK: }
3939
// CHECK: func mutateIt(_ x: PrivateSpecialMembers)

0 commit comments

Comments
 (0)