@@ -1283,8 +1283,6 @@ static bool canBridgeTypes(ImportTypeKind importKind) {
12831283 case ImportTypeKind::AuditedResult:
12841284 case ImportTypeKind::Parameter:
12851285 case ImportTypeKind::CompletionHandlerResultParameter:
1286- case ImportTypeKind::CFRetainedOutParameter:
1287- case ImportTypeKind::CFUnretainedOutParameter:
12881286 case ImportTypeKind::Property:
12891287 case ImportTypeKind::PropertyWithReferenceSemantics:
12901288 case ImportTypeKind::ObjCCollectionElement:
@@ -1311,8 +1309,6 @@ static bool isCFAudited(ImportTypeKind importKind) {
13111309 case ImportTypeKind::AuditedResult:
13121310 case ImportTypeKind::Parameter:
13131311 case ImportTypeKind::CompletionHandlerResultParameter:
1314- case ImportTypeKind::CFRetainedOutParameter:
1315- case ImportTypeKind::CFUnretainedOutParameter:
13161312 case ImportTypeKind::Property:
13171313 case ImportTypeKind::PropertyWithReferenceSemantics:
13181314 return true ;
@@ -1388,7 +1384,7 @@ static Type maybeImportNSErrorOutParameter(ClangImporter::Implementation &impl,
13881384
13891385static Type maybeImportCFOutParameter (ClangImporter::Implementation &impl,
13901386 Type importedType,
1391- ImportTypeKind importKind ) {
1387+ ImportTypeAttrs attrs ) {
13921388 PointerTypeKind PTK;
13931389 auto elementType = importedType->getAnyPointerElementType (PTK);
13941390 if (!elementType || PTK != PTK_UnsafeMutablePointer)
@@ -1414,7 +1410,7 @@ static Type maybeImportCFOutParameter(ClangImporter::Implementation &impl,
14141410 resultTy = OptionalType::get (resultTy);
14151411
14161412 PointerTypeKind pointerKind;
1417- if (importKind == ImportTypeKind ::CFRetainedOutParameter)
1413+ if (attrs. contains (ImportTypeAttr ::CFRetainedOutParameter) )
14181414 pointerKind = PTK_UnsafeMutablePointer;
14191415 else
14201416 pointerKind = PTK_AutoreleasingUnsafeMutablePointer;
@@ -1569,8 +1565,16 @@ static ImportedType adjustTypeForConcreteImport(
15691565 break ;
15701566
15711567 case ImportHint::OtherPointer:
1572- // Special-case AutoreleasingUnsafeMutablePointer<NSError?> parameters.
1573- if (importKind == ImportTypeKind::Parameter) {
1568+ // Remove 'Unmanaged' from audited CF out-parameters.
1569+ if (attrs.contains (ImportTypeAttr::CFRetainedOutParameter) ||
1570+ attrs.contains (ImportTypeAttr::CFUnretainedOutParameter)) {
1571+ if (Type outParamTy =
1572+ maybeImportCFOutParameter (impl, importedType, attrs)) {
1573+ importedType = outParamTy;
1574+ break ;
1575+ }
1576+ } else if (importKind == ImportTypeKind::Parameter) {
1577+ // Special-case AutoreleasingUnsafeMutablePointer<NSError?> parameters.
15741578 if (Type result = maybeImportNSErrorOutParameter (impl, importedType,
15751579 resugarNSErrorPointer)) {
15761580 importedType = result;
@@ -1579,16 +1583,6 @@ static ImportedType adjustTypeForConcreteImport(
15791583 }
15801584 }
15811585
1582- // Remove 'Unmanaged' from audited CF out-parameters.
1583- if (importKind == ImportTypeKind::CFRetainedOutParameter ||
1584- importKind == ImportTypeKind::CFUnretainedOutParameter) {
1585- if (Type outParamTy = maybeImportCFOutParameter (impl, importedType,
1586- importKind)) {
1587- importedType = outParamTy;
1588- break ;
1589- }
1590- }
1591-
15921586 break ;
15931587 }
15941588
@@ -2022,6 +2016,16 @@ ImportTypeAttrs swift::getImportTypeAttrs(const clang::Decl *D, bool isParam,
20222016 continue ;
20232017 }
20242018
2019+ if (isa<clang::CFReturnsRetainedAttr>(attr)) {
2020+ attrs |= ImportTypeAttr::CFRetainedOutParameter;
2021+ continue ;
2022+ }
2023+
2024+ if (isa<clang::CFReturnsNotRetainedAttr>(attr)) {
2025+ attrs |= ImportTypeAttr::CFUnretainedOutParameter;
2026+ continue ;
2027+ }
2028+
20252029 auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr);
20262030 if (!swiftAttr)
20272031 continue ;
@@ -2297,13 +2301,7 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
22972301
22982302static ImportTypeKind
22992303getImportTypeKindForParam (const clang::ParmVarDecl *param) {
2300- ImportTypeKind importKind = ImportTypeKind::Parameter;
2301- if (param->hasAttr <clang::CFReturnsRetainedAttr>())
2302- importKind = ImportTypeKind::CFRetainedOutParameter;
2303- else if (param->hasAttr <clang::CFReturnsNotRetainedAttr>())
2304- importKind = ImportTypeKind::CFUnretainedOutParameter;
2305-
2306- return importKind;
2304+ return ImportTypeKind::Parameter;
23072305}
23082306
23092307llvm::Optional<ClangImporter::Implementation::ImportParameterTypeResult>
0 commit comments