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"
@@ -8392,6 +8393,20 @@ SourceLoc swift::extractNearestSourceLoc(SafeUseOfCxxDeclDescriptor desc) {
83928393 return SourceLoc ();
83938394}
83948395
8396+ void swift::simple_display (llvm::raw_ostream &out,
8397+ CxxDeclExplicitSafetyDescriptor desc) {
8398+ out << " Checking if '" ;
8399+ if (auto namedDecl = dyn_cast<clang::NamedDecl>(desc.decl ))
8400+ out << namedDecl->getNameAsString ();
8401+ else
8402+ out << " <invalid decl>" ;
8403+ out << " ' is explicitly safe.\n " ;
8404+ }
8405+
8406+ SourceLoc swift::extractNearestSourceLoc (CxxDeclExplicitSafetyDescriptor desc) {
8407+ return SourceLoc ();
8408+ }
8409+
83958410CustomRefCountingOperationResult CustomRefCountingOperation::evaluate (
83968411 Evaluator &evaluator, CustomRefCountingOperationDescriptor desc) const {
83978412 auto swiftDecl = desc.decl ;
@@ -8469,9 +8484,11 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
84698484
84708485 // Handle records recursively.
84718486 if (auto recordDecl = clangType->getAsTagDecl ()) {
8472- auto safety =
8473- evaluateOrDefault (evaluator, ClangDeclExplicitSafety ({recordDecl}),
8474- ExplicitSafety::Unspecified);
8487+ // If we reached this point the types is not imported as a shared reference,
8488+ // so we don't need to check the bases whether they are shared references.
8489+ auto safety = evaluateOrDefault (
8490+ evaluator, ClangDeclExplicitSafety ({recordDecl, false }),
8491+ ExplicitSafety::Unspecified);
84758492 switch (safety) {
84768493 case ExplicitSafety::Unsafe:
84778494 return true ;
@@ -8486,10 +8503,9 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
84868503 return false ;
84878504}
84888505
8489- ExplicitSafety ClangDeclExplicitSafety::evaluate (
8490- Evaluator &evaluator,
8491- SafeUseOfCxxDeclDescriptor desc
8492- ) const {
8506+ ExplicitSafety
8507+ ClangDeclExplicitSafety::evaluate (Evaluator &evaluator,
8508+ CxxDeclExplicitSafetyDescriptor desc) const {
84938509 // FIXME: Somewhat duplicative with importAsUnsafe.
84948510 // FIXME: Also similar to hasPointerInSubobjects
84958511 // FIXME: should probably also subsume IsSafeUseOfCxxDecl
@@ -8502,7 +8518,11 @@ ExplicitSafety ClangDeclExplicitSafety::evaluate(
85028518 // Explicitly safe.
85038519 if (hasSwiftAttribute (decl, " safe" ))
85048520 return ExplicitSafety::Safe;
8505-
8521+
8522+ // Shared references are considered safe.
8523+ if (desc.isClass )
8524+ return ExplicitSafety::Safe;
8525+
85068526 // Enums are always safe.
85078527 if (isa<clang::EnumDecl>(decl))
85088528 return ExplicitSafety::Safe;
0 commit comments