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"
@@ -8407,6 +8408,20 @@ SourceLoc swift::extractNearestSourceLoc(SafeUseOfCxxDeclDescriptor desc) {
84078408 return SourceLoc ();
84088409}
84098410
8411+ void swift::simple_display (llvm::raw_ostream &out,
8412+ CxxDeclExplicitSafetyDescriptor desc) {
8413+ out << " Checking if '" ;
8414+ if (auto namedDecl = dyn_cast<clang::NamedDecl>(desc.decl ))
8415+ out << namedDecl->getNameAsString ();
8416+ else
8417+ out << " <invalid decl>" ;
8418+ out << " ' is explicitly safe.\n " ;
8419+ }
8420+
8421+ SourceLoc swift::extractNearestSourceLoc (CxxDeclExplicitSafetyDescriptor desc) {
8422+ return SourceLoc ();
8423+ }
8424+
84108425CustomRefCountingOperationResult CustomRefCountingOperation::evaluate (
84118426 Evaluator &evaluator, CustomRefCountingOperationDescriptor desc) const {
84128427 auto swiftDecl = desc.decl ;
@@ -8484,9 +8499,11 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
84848499
84858500 // Handle records recursively.
84868501 if (auto recordDecl = clangType->getAsTagDecl ()) {
8487- auto safety =
8488- evaluateOrDefault (evaluator, ClangDeclExplicitSafety ({recordDecl}),
8489- ExplicitSafety::Unspecified);
8502+ // If we reached this point the types is not imported as a shared reference,
8503+ // so we don't need to check the bases whether they are shared references.
8504+ auto safety = evaluateOrDefault (
8505+ evaluator, ClangDeclExplicitSafety ({recordDecl, false }),
8506+ ExplicitSafety::Unspecified);
84908507 switch (safety) {
84918508 case ExplicitSafety::Unsafe:
84928509 return true ;
@@ -8501,10 +8518,9 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
85018518 return false ;
85028519}
85038520
8504- ExplicitSafety ClangDeclExplicitSafety::evaluate (
8505- Evaluator &evaluator,
8506- SafeUseOfCxxDeclDescriptor desc
8507- ) const {
8521+ ExplicitSafety
8522+ ClangDeclExplicitSafety::evaluate (Evaluator &evaluator,
8523+ CxxDeclExplicitSafetyDescriptor desc) const {
85088524 // FIXME: Somewhat duplicative with importAsUnsafe.
85098525 // FIXME: Also similar to hasPointerInSubobjects
85108526 // FIXME: should probably also subsume IsSafeUseOfCxxDecl
@@ -8517,7 +8533,11 @@ ExplicitSafety ClangDeclExplicitSafety::evaluate(
85178533 // Explicitly safe.
85188534 if (hasSwiftAttribute (decl, " safe" ))
85198535 return ExplicitSafety::Safe;
8520-
8536+
8537+ // Shared references are considered safe.
8538+ if (desc.isClass )
8539+ return ExplicitSafety::Safe;
8540+
85218541 // Enums are always safe.
85228542 if (isa<clang::EnumDecl>(decl))
85238543 return ExplicitSafety::Safe;
0 commit comments