@@ -8723,51 +8723,6 @@ SourceLoc swift::extractNearestSourceLoc(SafeUseOfCxxDeclDescriptor desc) {
87238723 return SourceLoc ();
87248724}
87258725
8726- void swift::simple_display (llvm::raw_ostream &out,
8727- ClangTypeExplicitSafetyDescriptor desc) {
8728- out << " Checking if type '" << desc.type .getAsString ()
8729- << " ' is explicitly safe.\n " ;
8730- }
8731-
8732- SourceLoc swift::extractNearestSourceLoc (ClangTypeExplicitSafetyDescriptor desc) {
8733- return SourceLoc ();
8734- }
8735-
8736- ExplicitSafety ClangTypeExplicitSafety::evaluate (
8737- Evaluator &evaluator, ClangTypeExplicitSafetyDescriptor desc) const {
8738- auto clangType = desc.type ;
8739-
8740- // Handle pointers.
8741- auto pointeeType = clangType->getPointeeType ();
8742- if (!pointeeType.isNull ()) {
8743- // Function pointers are okay.
8744- if (pointeeType->isFunctionType ())
8745- return ExplicitSafety::Safe;
8746-
8747- // Pointers to record types are okay if they come in as foreign reference
8748- // types.
8749- if (auto *recordDecl = pointeeType->getAsRecordDecl ()) {
8750- if (hasImportAsRefAttr (recordDecl))
8751- return ExplicitSafety::Safe;
8752- }
8753-
8754- // All other pointers are considered unsafe.
8755- return ExplicitSafety::Unsafe;
8756- }
8757-
8758- // Handle records recursively.
8759- if (auto recordDecl = clangType->getAsTagDecl ()) {
8760- // If we reached this point the types is not imported as a shared reference,
8761- // so we don't need to check the bases whether they are shared references.
8762- return evaluateOrDefault (evaluator,
8763- ClangDeclExplicitSafety ({recordDecl, false }),
8764- ExplicitSafety::Unspecified);
8765- }
8766-
8767- // Everything else is safe.
8768- return ExplicitSafety::Safe;
8769- }
8770-
87718726void swift::simple_display (llvm::raw_ostream &out,
87728727 CxxDeclExplicitSafetyDescriptor desc) {
87738728 out << " Checking if '" ;
@@ -8839,11 +8794,43 @@ CustomRefCountingOperationResult CustomRefCountingOperation::evaluate(
88398794
88408795// / Check whether the given Clang type involves an unsafe type.
88418796static bool hasUnsafeType (Evaluator &evaluator, clang::QualType clangType) {
8797+ // Handle pointers.
8798+ auto pointeeType = clangType->getPointeeType ();
8799+ if (!pointeeType.isNull ()) {
8800+ // Function pointers are okay.
8801+ if (pointeeType->isFunctionType ())
8802+ return false ;
8803+
8804+ // Pointers to record types are okay if they come in as foreign reference
8805+ // types.
8806+ if (auto recordDecl = pointeeType->getAsRecordDecl ()) {
8807+ if (hasImportAsRefAttr (recordDecl))
8808+ return false ;
8809+ }
8810+
8811+ // All other pointers are considered unsafe.
8812+ return true ;
8813+ }
88428814
8843- auto safety =
8844- evaluateOrDefault (evaluator, ClangTypeExplicitSafety ({clangType}),
8845- ExplicitSafety::Unspecified);
8846- return safety == ExplicitSafety::Unsafe;
8815+ // Handle records recursively.
8816+ if (auto recordDecl = clangType->getAsTagDecl ()) {
8817+ // If we reached this point the types is not imported as a shared reference,
8818+ // so we don't need to check the bases whether they are shared references.
8819+ auto safety = evaluateOrDefault (
8820+ evaluator, ClangDeclExplicitSafety ({recordDecl, false }),
8821+ ExplicitSafety::Unspecified);
8822+ switch (safety) {
8823+ case ExplicitSafety::Unsafe:
8824+ return true ;
8825+
8826+ case ExplicitSafety::Safe:
8827+ case ExplicitSafety::Unspecified:
8828+ return false ;
8829+ }
8830+ }
8831+
8832+ // Everything else is safe.
8833+ return false ;
88478834}
88488835
88498836ExplicitSafety
0 commit comments