2424#include " swift/AST/Builtins.h"
2525#include " swift/AST/ClangModuleLoader.h"
2626#include " swift/AST/ConcreteDeclRef.h"
27+ #include " swift/AST/Decl.h"
2728#include " swift/AST/DiagnosticEngine.h"
2829#include " swift/AST/DiagnosticsClangImporter.h"
2930#include " swift/AST/DiagnosticsSema.h"
@@ -8391,6 +8392,20 @@ SourceLoc swift::extractNearestSourceLoc(SafeUseOfCxxDeclDescriptor desc) {
83918392 return SourceLoc ();
83928393}
83938394
8395+ void swift::simple_display (llvm::raw_ostream &out,
8396+ CxxDeclExplicitSafetyDescriptor desc) {
8397+ out << " Checking if '" ;
8398+ if (auto namedDecl = dyn_cast<clang::NamedDecl>(desc.decl ))
8399+ out << namedDecl->getNameAsString ();
8400+ else
8401+ out << " <invalid decl>" ;
8402+ out << " ' is explicitly safe.\n " ;
8403+ }
8404+
8405+ SourceLoc swift::extractNearestSourceLoc (CxxDeclExplicitSafetyDescriptor desc) {
8406+ return SourceLoc ();
8407+ }
8408+
83948409CustomRefCountingOperationResult CustomRefCountingOperation::evaluate (
83958410 Evaluator &evaluator, CustomRefCountingOperationDescriptor desc) const {
83968411 auto swiftDecl = desc.decl ;
@@ -8468,9 +8483,11 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
84688483
84698484 // Handle records recursively.
84708485 if (auto recordDecl = clangType->getAsTagDecl ()) {
8471- auto safety =
8472- evaluateOrDefault (evaluator, ClangDeclExplicitSafety ({recordDecl}),
8473- ExplicitSafety::Unspecified);
8486+ // If we reached this point the types is not imported as a shared reference,
8487+ // so we don't need to check the bases whether they are shared references.
8488+ auto safety = evaluateOrDefault (
8489+ evaluator, ClangDeclExplicitSafety ({recordDecl, false }),
8490+ ExplicitSafety::Unspecified);
84748491 switch (safety) {
84758492 case ExplicitSafety::Unsafe:
84768493 return true ;
@@ -8485,10 +8502,9 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
84858502 return false ;
84868503}
84878504
8488- ExplicitSafety ClangDeclExplicitSafety::evaluate (
8489- Evaluator &evaluator,
8490- SafeUseOfCxxDeclDescriptor desc
8491- ) const {
8505+ ExplicitSafety
8506+ ClangDeclExplicitSafety::evaluate (Evaluator &evaluator,
8507+ CxxDeclExplicitSafetyDescriptor desc) const {
84928508 // FIXME: Somewhat duplicative with importAsUnsafe.
84938509 // FIXME: Also similar to hasPointerInSubobjects
84948510 // FIXME: should probably also subsume IsSafeUseOfCxxDecl
@@ -8501,7 +8517,11 @@ ExplicitSafety ClangDeclExplicitSafety::evaluate(
85018517 // Explicitly safe.
85028518 if (hasSwiftAttribute (decl, " safe" ))
85038519 return ExplicitSafety::Safe;
8504-
8520+
8521+ // Shared references are considered safe.
8522+ if (desc.isClass )
8523+ return ExplicitSafety::Safe;
8524+
85058525 // Enums are always safe.
85068526 if (isa<clang::EnumDecl>(decl))
85078527 return ExplicitSafety::Safe;
0 commit comments