Skip to content

Commit 9153155

Browse files
authored
Merge pull request #79458 from swiftlang/gaborh/unsafe-cleanup
2 parents bdf2294 + c859557 commit 9153155

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8551,36 +8551,6 @@ bool swift::importer::isMutabilityAttr(const clang::SwiftAttrAttr *swiftAttr) {
85518551
swiftAttr->getAttribute() == "nonmutating";
85528552
}
85538553

8554-
static bool importAsUnsafe(ClangImporter::Implementation &impl,
8555-
const clang::NamedDecl *decl,
8556-
const Decl *MappedDecl) {
8557-
auto &context = impl.SwiftContext;
8558-
if (!context.LangOpts.hasFeature(Feature::AllowUnsafeAttribute))
8559-
return false;
8560-
8561-
if (isa<clang::CXXMethodDecl>(decl) &&
8562-
!evaluateOrDefault(context.evaluator, IsSafeUseOfCxxDecl({decl}), {}))
8563-
return true;
8564-
8565-
if (isa<ClassDecl>(MappedDecl))
8566-
return false;
8567-
8568-
// Most STL containers have std::allocator as their default allocator. We need
8569-
// to consider std::allocator safe for the STL containers to be ever
8570-
// considered safe.
8571-
if (decl->isInStdNamespace() && decl->getIdentifier() &&
8572-
decl->getName() == "allocator")
8573-
return false;
8574-
8575-
if (const auto *record = dyn_cast<clang::RecordDecl>(decl))
8576-
return evaluateOrDefault(
8577-
context.evaluator,
8578-
ClangTypeEscapability({record->getTypeForDecl(), &impl, false}),
8579-
CxxEscapability::Unknown) == CxxEscapability::Unknown;
8580-
8581-
return false;
8582-
}
8583-
85848554
void ClangImporter::Implementation::importNontrivialAttribute(
85858555
Decl *MappedDecl, llvm::StringRef AttrString) {
85868556
bool cached = true;
@@ -8767,7 +8737,11 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
87678737
importNontrivialAttribute(MappedDecl, swiftAttr->getAttribute());
87688738
}
87698739

8770-
if (seenUnsafe || importAsUnsafe(*this, ClangDecl, MappedDecl)) {
8740+
bool importUnsafeHeuristic =
8741+
isa<clang::CXXMethodDecl>(ClangDecl) &&
8742+
!evaluateOrDefault(SwiftContext.evaluator,
8743+
IsSafeUseOfCxxDecl({ClangDecl}), {});
8744+
if (seenUnsafe || importUnsafeHeuristic) {
87718745
auto attr = new (SwiftContext) UnsafeAttr(/*implicit=*/!seenUnsafe);
87728746
MappedDecl->getAttrs().add(attr);
87738747
}

test/Interop/Cxx/class/safe-interop-mode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct SWIFT_ESCAPABLE Owner {};
3434

3535
struct Unannotated {
3636
Unannotated();
37+
int *pointer;
3738
};
3839

3940
struct SWIFT_UNSAFE_REFERENCE UnsafeReference {};

0 commit comments

Comments
 (0)