@@ -8226,18 +8226,27 @@ bool swift::importer::isMutabilityAttr(const clang::SwiftAttrAttr *swiftAttr) {
8226
8226
swiftAttr->getAttribute () == " nonmutating" ;
8227
8227
}
8228
8228
8229
- static bool importAsUnsafe (ASTContext &context, const clang::RecordDecl *decl,
8229
+ static bool importAsUnsafe (ASTContext &context, const clang::NamedDecl *decl,
8230
8230
const Decl *MappedDecl) {
8231
8231
if (!context.LangOpts .hasFeature (Feature::SafeInterop) ||
8232
- !context.LangOpts .hasFeature (Feature::AllowUnsafeAttribute) || !decl )
8232
+ !context.LangOpts .hasFeature (Feature::AllowUnsafeAttribute))
8233
8233
return false ;
8234
8234
8235
+ if (isa<clang::CXXMethodDecl>(decl) &&
8236
+ !evaluateOrDefault (context.evaluator , IsSafeUseOfCxxDecl ({decl, context}),
8237
+ {}))
8238
+ return true ;
8239
+
8235
8240
if (isa<ClassDecl>(MappedDecl))
8236
8241
return false ;
8237
8242
8238
- return evaluateOrDefault (
8239
- context.evaluator , ClangTypeEscapability ({decl->getTypeForDecl ()}),
8240
- CxxEscapability::Unknown) == CxxEscapability::Unknown;
8243
+ if (const auto *record = dyn_cast<clang::RecordDecl>(decl))
8244
+ return evaluateOrDefault (context.evaluator ,
8245
+ ClangTypeEscapability ({record->getTypeForDecl ()}),
8246
+ CxxEscapability::Unknown) ==
8247
+ CxxEscapability::Unknown;
8248
+
8249
+ return false ;
8241
8250
}
8242
8251
8243
8252
void
@@ -8419,9 +8428,7 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
8419
8428
}
8420
8429
}
8421
8430
8422
- if (seenUnsafe ||
8423
- importAsUnsafe (SwiftContext, dyn_cast<clang::RecordDecl>(ClangDecl),
8424
- MappedDecl)) {
8431
+ if (seenUnsafe || importAsUnsafe (SwiftContext, ClangDecl, MappedDecl)) {
8425
8432
auto attr = new (SwiftContext) UnsafeAttr (/* implicit=*/ !seenUnsafe);
8426
8433
MappedDecl->getAttrs ().add (attr);
8427
8434
}
0 commit comments