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"
@@ -8407,6 +8408,20 @@ SourceLoc swift::extractNearestSourceLoc(SafeUseOfCxxDeclDescriptor desc) {
8407
8408
return SourceLoc ();
8408
8409
}
8409
8410
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
+
8410
8425
CustomRefCountingOperationResult CustomRefCountingOperation::evaluate (
8411
8426
Evaluator &evaluator, CustomRefCountingOperationDescriptor desc) const {
8412
8427
auto swiftDecl = desc.decl ;
@@ -8484,9 +8499,11 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
8484
8499
8485
8500
// Handle records recursively.
8486
8501
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);
8490
8507
switch (safety) {
8491
8508
case ExplicitSafety::Unsafe:
8492
8509
return true ;
@@ -8501,10 +8518,9 @@ static bool hasUnsafeType(Evaluator &evaluator, clang::QualType clangType) {
8501
8518
return false ;
8502
8519
}
8503
8520
8504
- ExplicitSafety ClangDeclExplicitSafety::evaluate (
8505
- Evaluator &evaluator,
8506
- SafeUseOfCxxDeclDescriptor desc
8507
- ) const {
8521
+ ExplicitSafety
8522
+ ClangDeclExplicitSafety::evaluate (Evaluator &evaluator,
8523
+ CxxDeclExplicitSafetyDescriptor desc) const {
8508
8524
// FIXME: Somewhat duplicative with importAsUnsafe.
8509
8525
// FIXME: Also similar to hasPointerInSubobjects
8510
8526
// FIXME: should probably also subsume IsSafeUseOfCxxDecl
@@ -8517,7 +8533,11 @@ ExplicitSafety ClangDeclExplicitSafety::evaluate(
8517
8533
// Explicitly safe.
8518
8534
if (hasSwiftAttribute (decl, " safe" ))
8519
8535
return ExplicitSafety::Safe;
8520
-
8536
+
8537
+ // Shared references are considered safe.
8538
+ if (desc.isClass )
8539
+ return ExplicitSafety::Safe;
8540
+
8521
8541
// Enums are always safe.
8522
8542
if (isa<clang::EnumDecl>(decl))
8523
8543
return ExplicitSafety::Safe;
0 commit comments