@@ -8640,6 +8640,51 @@ SourceLoc swift::extractNearestSourceLoc(SafeUseOfCxxDeclDescriptor desc) {
86408640 return SourceLoc ();
86418641}
86428642
8643+ void swift::simple_display (llvm::raw_ostream &out,
8644+ ClangTypeExplicitSafetyDescriptor desc) {
8645+ auto qt = static_cast <clang::QualType>(desc.type );
8646+ out << " Checking if type '" << qt.getAsString () << " ' is explicitly safe.\n " ;
8647+ }
8648+
8649+ SourceLoc swift::extractNearestSourceLoc (ClangTypeExplicitSafetyDescriptor desc) {
8650+ return SourceLoc ();
8651+ }
8652+
8653+ ExplicitSafety ClangTypeExplicitSafety::evaluate (
8654+ Evaluator &evaluator, ClangTypeExplicitSafetyDescriptor desc) const {
8655+ auto clangType = static_cast <clang::QualType>(desc.type );
8656+
8657+ // Handle pointers.
8658+ auto pointeeType = clangType->getPointeeType ();
8659+ if (!pointeeType.isNull ()) {
8660+ // Function pointers are okay.
8661+ if (pointeeType->isFunctionType ())
8662+ return ExplicitSafety::Safe;
8663+
8664+ // Pointers to record types are okay if they come in as foreign reference
8665+ // types.
8666+ if (auto *recordDecl = pointeeType->getAsRecordDecl ()) {
8667+ if (hasImportAsRefAttr (recordDecl))
8668+ return ExplicitSafety::Safe;
8669+ }
8670+
8671+ // All other pointers are considered unsafe.
8672+ return ExplicitSafety::Unsafe;
8673+ }
8674+
8675+ // Handle records recursively.
8676+ if (auto recordDecl = clangType->getAsTagDecl ()) {
8677+ // If we reached this point the types is not imported as a shared reference,
8678+ // so we don't need to check the bases whether they are shared references.
8679+ return evaluateOrDefault (evaluator,
8680+ ClangDeclExplicitSafety ({recordDecl, false }),
8681+ ExplicitSafety::Unspecified);
8682+ }
8683+
8684+ // Everything else is safe.
8685+ return ExplicitSafety::Safe;
8686+ }
8687+
86438688void swift::simple_display (llvm::raw_ostream &out,
86448689 CxxDeclExplicitSafetyDescriptor desc) {
86458690 out << " Checking if '" ;
@@ -8711,49 +8756,16 @@ CustomRefCountingOperationResult CustomRefCountingOperation::evaluate(
87118756
87128757// / Check whether the given Clang type involves an unsafe type.
87138758static bool hasUnsafeType (Evaluator &evaluator, clang::QualType clangType) {
8714- // Handle pointers.
8715- auto pointeeType = clangType->getPointeeType ();
8716- if (!pointeeType.isNull ()) {
8717- // Function pointers are okay.
8718- if (pointeeType->isFunctionType ())
8719- return false ;
8720-
8721- // Pointers to record types are okay if they come in as foreign reference
8722- // types.
8723- if (auto recordDecl = pointeeType->getAsRecordDecl ()) {
8724- if (hasImportAsRefAttr (recordDecl))
8725- return false ;
8726- }
8727-
8728- // All other pointers are considered unsafe.
8729- return true ;
8730- }
87318759
8732- // Handle records recursively.
8733- if (auto recordDecl = clangType->getAsTagDecl ()) {
8734- // If we reached this point the types is not imported as a shared reference,
8735- // so we don't need to check the bases whether they are shared references.
8736- auto safety = evaluateOrDefault (
8737- evaluator, ClangDeclExplicitSafety ({recordDecl, false }),
8738- ExplicitSafety::Unspecified);
8739- switch (safety) {
8740- case ExplicitSafety::Unsafe:
8741- return true ;
8742-
8743- case ExplicitSafety::Safe:
8744- case ExplicitSafety::Unspecified:
8745- return false ;
8746- }
8747- }
8748-
8749- // Everything else is safe.
8750- return false ;
8760+ auto safety =
8761+ evaluateOrDefault (evaluator, ClangTypeExplicitSafety ({clangType}),
8762+ ExplicitSafety::Unspecified);
8763+ return safety == ExplicitSafety::Unsafe;
87518764}
87528765
87538766ExplicitSafety
87548767ClangDeclExplicitSafety::evaluate (Evaluator &evaluator,
87558768 CxxDeclExplicitSafetyDescriptor desc) const {
8756- // FIXME: Somewhat duplicative with importAsUnsafe.
87578769 // FIXME: Also similar to hasPointerInSubobjects
87588770 // FIXME: should probably also subsume IsSafeUseOfCxxDecl
87598771
0 commit comments