24
24
#include " swift/AST/Builtins.h"
25
25
#include " swift/AST/ClangModuleLoader.h"
26
26
#include " swift/AST/ConcreteDeclRef.h"
27
+ #include " swift/AST/Decl.h"
27
28
#include " swift/AST/DiagnosticEngine.h"
28
29
#include " swift/AST/DiagnosticsClangImporter.h"
29
30
#include " swift/AST/DiagnosticsSema.h"
@@ -8391,6 +8392,20 @@ SourceLoc swift::extractNearestSourceLoc(SafeUseOfCxxDeclDescriptor desc) {
8391
8392
return SourceLoc ();
8392
8393
}
8393
8394
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
+
8394
8409
CustomRefCountingOperationResult CustomRefCountingOperation::evaluate (
8395
8410
Evaluator &evaluator, CustomRefCountingOperationDescriptor desc) const {
8396
8411
auto swiftDecl = desc.decl ;
@@ -8468,9 +8483,11 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
8468
8483
8469
8484
// Handle records recursively.
8470
8485
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);
8474
8491
switch (safety) {
8475
8492
case ExplicitSafety::Unsafe:
8476
8493
return true ;
@@ -8485,10 +8502,9 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
8485
8502
return false ;
8486
8503
}
8487
8504
8488
- ExplicitSafety ClangDeclExplicitSafety::evaluate (
8489
- Evaluator &evaluator,
8490
- SafeUseOfCxxDeclDescriptor desc
8491
- ) const {
8505
+ ExplicitSafety
8506
+ ClangDeclExplicitSafety::evaluate (Evaluator &evaluator,
8507
+ CxxDeclExplicitSafetyDescriptor desc) const {
8492
8508
// FIXME: Somewhat duplicative with importAsUnsafe.
8493
8509
// FIXME: Also similar to hasPointerInSubobjects
8494
8510
// FIXME: should probably also subsume IsSafeUseOfCxxDecl
@@ -8501,7 +8517,11 @@ ExplicitSafety ClangDeclExplicitSafety::evaluate(
8501
8517
// Explicitly safe.
8502
8518
if (hasSwiftAttribute (decl, " safe" ))
8503
8519
return ExplicitSafety::Safe;
8504
-
8520
+
8521
+ // Shared references are considered safe.
8522
+ if (desc.isClass )
8523
+ return ExplicitSafety::Safe;
8524
+
8505
8525
// Enums are always safe.
8506
8526
if (isa<clang::EnumDecl>(decl))
8507
8527
return ExplicitSafety::Safe;
0 commit comments