Skip to content

Commit 781850c

Browse files
committed
[cxx-interop] Simplify logic in IsSafeUseOfCxxDecl; fix bug for pointer types.
Previously types containing pointers would mark all C++ methods as unsafe.
1 parent 080b3a3 commit 781850c

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6041,7 +6041,6 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
60416041
SafeUseOfCxxDeclDescriptor desc) const {
60426042
const clang::Decl *decl = desc.decl;
60436043
const clang::CXXRecordDecl *recordDecl = nullptr;
6044-
bool isCxxMethod = false;
60456044
bool cxxMethodIsSafe = true;
60466045

60476046
if (auto method = dyn_cast<clang::CXXMethodDecl>(decl)) {
@@ -6071,7 +6070,6 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
60716070
}
60726071
}
60736072

6074-
isCxxMethod = true;
60756073
recordDecl = method->getParent();
60766074
} else if (auto cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(decl)) {
60776075
recordDecl = cxxRecordDecl;
@@ -6090,19 +6088,10 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
60906088
if (semanticsKind == CxxRecordSemanticsKind::Reference)
60916089
return true;
60926090

6093-
// Cannot return projections.
6094-
if (semanticsKind == CxxRecordSemanticsKind::Trivial ||
6095-
semanticsKind == CxxRecordSemanticsKind::Owned)
6096-
return cxxMethodIsSafe;
60976091

6098-
if (semanticsKind == CxxRecordSemanticsKind::ExplicitlyUnsafe)
6099-
return cxxMethodIsSafe;
6100-
6101-
assert(semanticsKind == CxxRecordSemanticsKind::UnsafePointerMember);
6102-
// We can't dis-allow *all* APIs that potentially return unsafe projections
6103-
// because this would break ObjC interop. So only do this when it's a known
6104-
// C++ API (maybe this could warn in a specific compiler mode, though).
6105-
return !isCxxMethod;
6092+
// All other record semantics kinds are some varient of an "owned" type, so
6093+
// dis-allow potential projections.
6094+
return cxxMethodIsSafe;
61066095
}
61076096

61086097
void swift::simple_display(llvm::raw_ostream &out,

0 commit comments

Comments
 (0)