Skip to content

Commit 39a837c

Browse files
authored
Merge pull request #67115 from apple/egorzhdan/cxx-semantics-kind
[cxx-interop] Tweak C++ type semantics detection
2 parents e3621b0 + 6e7fb32 commit 39a837c

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

include/swift/ClangImporter/ClangImporterRequests.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,8 @@ enum class CxxRecordSemanticsKind {
306306
MoveOnly,
307307
Reference,
308308
Iterator,
309-
// An API that has be annotated as explicitly unsafe, but still importable.
310-
// TODO: we should rename these APIs.
311-
ExplicitlyUnsafe,
312309
// A record that is either not copyable or not destructible.
313310
MissingLifetimeOperation,
314-
// A record that contains a pointer (aka non-trivial type).
315-
UnsafePointerMember,
316311
// A C++ record that represents a Swift class type exposed to C++ from Swift.
317312
SwiftClassType
318313
};

lib/ClangImporter/ClangImporter.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6718,10 +6718,6 @@ CxxRecordSemantics::evaluate(Evaluator &evaluator,
67186718
return CxxRecordSemanticsKind::MissingLifetimeOperation;
67196719
}
67206720

6721-
if (hasUnsafeAPIAttr(cxxDecl)) {
6722-
return CxxRecordSemanticsKind::ExplicitlyUnsafe;
6723-
}
6724-
67256721
if (hasOwnedValueAttr(cxxDecl)) {
67266722
return CxxRecordSemanticsKind::Owned;
67276723
}
@@ -6730,11 +6726,6 @@ CxxRecordSemantics::evaluate(Evaluator &evaluator,
67306726
return CxxRecordSemanticsKind::Iterator;
67316727
}
67326728

6733-
if (!hasCustomCopyOrMoveConstructor(cxxDecl) &&
6734-
hasPointerInSubobjects(cxxDecl)) {
6735-
return CxxRecordSemanticsKind::UnsafePointerMember;
6736-
}
6737-
67386729
if (hasCopyTypeOperations(cxxDecl)) {
67396730
return CxxRecordSemanticsKind::Owned;
67406731
}

lib/Sema/CSDiagnostics.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4073,9 +4073,6 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc,
40734073
name.getBaseIdentifier().str());
40744074
ctx.Diags.diagnose(loc, diag::iterator_potentially_unsafe);
40754075
} else {
4076-
assert(methodSemantics ==
4077-
CxxRecordSemanticsKind::UnsafePointerMember);
4078-
40794076
auto baseSwiftLoc = ctx.getClangModuleLoader()->importSourceLocation(
40804077
cxxRecord->getLocation());
40814078

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ struct StructWithSubobjectPrivateDefaultedDestructor {
112112
StructWithPrivateDefaultedDestructor subobject;
113113
};
114114

115+
struct StructWithDeletedCopyConstructor {
116+
StructWithDeletedCopyConstructor(
117+
const StructWithDeletedCopyConstructor &other) = delete;
118+
};
119+
120+
struct StructWithMoveConstructorAndDeletedCopyConstructor {
121+
StructWithMoveConstructorAndDeletedCopyConstructor() {}
122+
StructWithMoveConstructorAndDeletedCopyConstructor(
123+
const StructWithMoveConstructorAndDeletedCopyConstructor &other) = delete;
124+
StructWithMoveConstructorAndDeletedCopyConstructor(
125+
StructWithMoveConstructorAndDeletedCopyConstructor &&other) {}
126+
~StructWithMoveConstructorAndDeletedCopyConstructor(){};
127+
};
128+
115129
struct StructWithDeletedDestructor {
116130
~StructWithDeletedDestructor() = delete;
117131
};
@@ -148,6 +162,22 @@ struct StructNonCopyableTriviallyMovable {
148162
~StructNonCopyableTriviallyMovable() = default;
149163
};
150164

165+
/// Similar to std::unique_ptr
166+
struct StructWithPointerNonCopyableTriviallyMovable {
167+
int *ptr = nullptr;
168+
169+
StructWithPointerNonCopyableTriviallyMovable() = default;
170+
StructWithPointerNonCopyableTriviallyMovable(
171+
const StructWithPointerNonCopyableTriviallyMovable &other) = delete;
172+
StructWithPointerNonCopyableTriviallyMovable(
173+
StructWithPointerNonCopyableTriviallyMovable &&other) = default;
174+
~StructWithPointerNonCopyableTriviallyMovable() = default;
175+
};
176+
177+
struct StructWithPointerNonCopyableTriviallyMovableField {
178+
StructWithPointerNonCopyableTriviallyMovable p = {};
179+
};
180+
151181
struct StructNonCopyableNonMovable {
152182
StructNonCopyableNonMovable(const StructNonCopyableNonMovable &) = delete;
153183
StructNonCopyableNonMovable(StructNonCopyableNonMovable &&) = default;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// CHECK-NOT: StructWithInheritedPrivateDefaultedCopyConstructor
77
// CHECK-NOT: StructWithSubobjectPrivateDefaultedCopyConstructor
88
// CHECK-NOT: StructNonCopyableTriviallyMovable
9+
// CHECK-NOT: StructWithPointerNonCopyableTriviallyMovable
10+
// CHECK-NOT: StructWithPointerNonCopyableTriviallyMovableField
911
// CHECK-NOT: StructNonCopyableNonMovable
1012
// CHECK-NOT: StructWithMoveConstructor
1113
// CHECK-NOT: StructWithInheritedMoveConstructor
@@ -16,6 +18,8 @@
1618
// CHECK-NOT: StructWithPrivateDefaultedDestructor
1719
// CHECK-NOT: StructWithInheritedPrivateDefaultedDestructor
1820
// CHECK-NOT: StructWithSubobjectPrivateDefaultedDestructor
21+
// CHECK-NOT: StructWithDeletedCopyConstructor
22+
// CHECK-NOT: StructWithMoveConstructorAndDeletedCopyConstructor
1923
// CHECK-NOT: StructWithDeletedDestructor
2024
// CHECK-NOT: StructWithInheritedDeletedDestructor
2125
// CHECK-NOT: StructWithSubobjectDeletedDestructor

0 commit comments

Comments
 (0)