@@ -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-
85848554void 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 }
0 commit comments