Skip to content

Commit 09384be

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 3498ff9 commit 09384be

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
@@ -5980,7 +5980,6 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
59805980
SafeUseOfCxxDeclDescriptor desc) const {
59815981
const clang::Decl *decl = desc.decl;
59825982
const clang::CXXRecordDecl *recordDecl = nullptr;
5983-
bool isCxxMethod = false;
59845983
bool cxxMethodIsSafe = true;
59855984

59865985
if (auto method = dyn_cast<clang::CXXMethodDecl>(decl)) {
@@ -6010,7 +6009,6 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
60106009
}
60116010
}
60126011

6013-
isCxxMethod = true;
60146012
recordDecl = method->getParent();
60156013
} else if (auto cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(decl)) {
60166014
recordDecl = cxxRecordDecl;
@@ -6029,19 +6027,10 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
60296027
if (semanticsKind == CxxRecordSemanticsKind::Reference)
60306028
return true;
60316029

6032-
// Cannot return projections.
6033-
if (semanticsKind == CxxRecordSemanticsKind::Trivial ||
6034-
semanticsKind == CxxRecordSemanticsKind::Owned)
6035-
return cxxMethodIsSafe;
60366030

6037-
if (semanticsKind == CxxRecordSemanticsKind::ExplicitlyUnsafe)
6038-
return cxxMethodIsSafe;
6039-
6040-
assert(semanticsKind == CxxRecordSemanticsKind::UnsafePointerMember);
6041-
// We can't dis-allow *all* APIs that potentially return unsafe projections
6042-
// because this would break ObjC interop. So only do this when it's a known
6043-
// C++ API (maybe this could warn in a specific compiler mode, though).
6044-
return !isCxxMethod;
6031+
// All other record semantics kinds are some varient of an "owned" type, so
6032+
// dis-allow potential projections.
6033+
return cxxMethodIsSafe;
60456034
}
60466035

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

0 commit comments

Comments
 (0)