@@ -8551,36 +8551,6 @@ bool swift::importer::isMutabilityAttr(const clang::SwiftAttrAttr *swiftAttr) {
8551
8551
swiftAttr->getAttribute () == " nonmutating" ;
8552
8552
}
8553
8553
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
-
8584
8554
void ClangImporter::Implementation::importNontrivialAttribute (
8585
8555
Decl *MappedDecl, llvm::StringRef AttrString) {
8586
8556
bool cached = true ;
@@ -8767,7 +8737,11 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
8767
8737
importNontrivialAttribute (MappedDecl, swiftAttr->getAttribute ());
8768
8738
}
8769
8739
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) {
8771
8745
auto attr = new (SwiftContext) UnsafeAttr (/* implicit=*/ !seenUnsafe);
8772
8746
MappedDecl->getAttrs ().add (attr);
8773
8747
}
0 commit comments