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