Skip to content

Commit 7018c55

Browse files
authored
Merge pull request #63678 from apple/egorzhdan/cxx-unsafe-iterator-box
[cxx-interop] Treat C++ structs that store iterators as unsafe
2 parents 4696610 + fc5215f commit 7018c55

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6274,6 +6274,9 @@ static bool hasPointerInSubobjects(const clang::CXXRecordDecl *decl) {
62746274
hasUnsafeAPIAttr(cxxRecord))
62756275
return false;
62766276

6277+
if (hasIteratorAPIAttr(cxxRecord) || isIterator(cxxRecord))
6278+
return true;
6279+
62776280
if (hasPointerInSubobjects(cxxRecord))
62786281
return true;
62796282
}

test/Interop/Cxx/class/Inputs/type-classification.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,20 @@ struct HasUnsupportedUsingShadow : DependentParent<int> {
197197
using typename DependentParent<int>::Child;
198198
};
199199

200+
struct __attribute__((swift_attr("import_iterator"))) Iterator {
201+
int idx;
202+
};
203+
204+
struct HasMethodThatReturnsIterator {
205+
Iterator getIterator() const;
206+
};
207+
208+
struct IteratorBox {
209+
Iterator it;
210+
};
211+
212+
struct HasMethodThatReturnsIteratorBox {
213+
IteratorBox getIteratorBox() const;
214+
};
215+
200216
#endif // TEST_INTEROP_CXX_CLASS_INPUTS_TYPE_CLASSIFICATION_H

test/Interop/Cxx/class/type-classification-module-interface.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@
1818
// CHECK-NOT: StructWithDeletedDestructor
1919
// CHECK-NOT: StructWithInheritedDeletedDestructor
2020
// CHECK-NOT: StructWithSubobjectDeletedDestructor
21+
22+
// CHECK: struct Iterator {
23+
// CHECK: }
24+
25+
// CHECK: struct HasMethodThatReturnsIterator {
26+
// CHECK: func __getIteratorUnsafe() -> Iterator
27+
// CHECK: }
28+
29+
// CHECK: struct IteratorBox {
30+
// CHECK: }
31+
32+
// CHECK: struct HasMethodThatReturnsIteratorBox {
33+
// CHECK: func __getIteratorBoxUnsafe() -> IteratorBox
34+
// CHECK: }

0 commit comments

Comments
 (0)