Skip to content

[cxx-interop] Treat C++ structs that store iterators as unsafe #63678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6274,6 +6274,9 @@ static bool hasPointerInSubobjects(const clang::CXXRecordDecl *decl) {
hasUnsafeAPIAttr(cxxRecord))
return false;

if (hasIteratorAPIAttr(cxxRecord) || isIterator(cxxRecord))
return true;

if (hasPointerInSubobjects(cxxRecord))
return true;
}
Expand Down
16 changes: 16 additions & 0 deletions test/Interop/Cxx/class/Inputs/type-classification.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,20 @@ struct HasUnsupportedUsingShadow : DependentParent<int> {
using typename DependentParent<int>::Child;
};

struct __attribute__((swift_attr("import_iterator"))) Iterator {
int idx;
};

struct HasMethodThatReturnsIterator {
Iterator getIterator() const;
};

struct IteratorBox {
Iterator it;
};

struct HasMethodThatReturnsIteratorBox {
IteratorBox getIteratorBox() const;
};

#endif // TEST_INTEROP_CXX_CLASS_INPUTS_TYPE_CLASSIFICATION_H
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@
// CHECK-NOT: StructWithDeletedDestructor
// CHECK-NOT: StructWithInheritedDeletedDestructor
// CHECK-NOT: StructWithSubobjectDeletedDestructor

// CHECK: struct Iterator {
// CHECK: }

// CHECK: struct HasMethodThatReturnsIterator {
// CHECK: func __getIteratorUnsafe() -> Iterator
// CHECK: }

// CHECK: struct IteratorBox {
// CHECK: }

// CHECK: struct HasMethodThatReturnsIteratorBox {
// CHECK: func __getIteratorBoxUnsafe() -> IteratorBox
// CHECK: }