@@ -1283,8 +1283,6 @@ static bool canBridgeTypes(ImportTypeKind importKind) {
1283
1283
case ImportTypeKind::AuditedResult:
1284
1284
case ImportTypeKind::Parameter:
1285
1285
case ImportTypeKind::CompletionHandlerResultParameter:
1286
- case ImportTypeKind::CFRetainedOutParameter:
1287
- case ImportTypeKind::CFUnretainedOutParameter:
1288
1286
case ImportTypeKind::Property:
1289
1287
case ImportTypeKind::PropertyWithReferenceSemantics:
1290
1288
case ImportTypeKind::ObjCCollectionElement:
@@ -1311,8 +1309,6 @@ static bool isCFAudited(ImportTypeKind importKind) {
1311
1309
case ImportTypeKind::AuditedResult:
1312
1310
case ImportTypeKind::Parameter:
1313
1311
case ImportTypeKind::CompletionHandlerResultParameter:
1314
- case ImportTypeKind::CFRetainedOutParameter:
1315
- case ImportTypeKind::CFUnretainedOutParameter:
1316
1312
case ImportTypeKind::Property:
1317
1313
case ImportTypeKind::PropertyWithReferenceSemantics:
1318
1314
return true ;
@@ -1388,7 +1384,7 @@ static Type maybeImportNSErrorOutParameter(ClangImporter::Implementation &impl,
1388
1384
1389
1385
static Type maybeImportCFOutParameter (ClangImporter::Implementation &impl,
1390
1386
Type importedType,
1391
- ImportTypeKind importKind ) {
1387
+ ImportTypeAttrs attrs ) {
1392
1388
PointerTypeKind PTK;
1393
1389
auto elementType = importedType->getAnyPointerElementType (PTK);
1394
1390
if (!elementType || PTK != PTK_UnsafeMutablePointer)
@@ -1414,7 +1410,7 @@ static Type maybeImportCFOutParameter(ClangImporter::Implementation &impl,
1414
1410
resultTy = OptionalType::get (resultTy);
1415
1411
1416
1412
PointerTypeKind pointerKind;
1417
- if (importKind == ImportTypeKind ::CFRetainedOutParameter)
1413
+ if (attrs. contains (ImportTypeAttr ::CFRetainedOutParameter) )
1418
1414
pointerKind = PTK_UnsafeMutablePointer;
1419
1415
else
1420
1416
pointerKind = PTK_AutoreleasingUnsafeMutablePointer;
@@ -1569,8 +1565,16 @@ static ImportedType adjustTypeForConcreteImport(
1569
1565
break ;
1570
1566
1571
1567
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.
1574
1578
if (Type result = maybeImportNSErrorOutParameter (impl, importedType,
1575
1579
resugarNSErrorPointer)) {
1576
1580
importedType = result;
@@ -1579,16 +1583,6 @@ static ImportedType adjustTypeForConcreteImport(
1579
1583
}
1580
1584
}
1581
1585
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
-
1592
1586
break ;
1593
1587
}
1594
1588
@@ -2022,6 +2016,16 @@ ImportTypeAttrs swift::getImportTypeAttrs(const clang::Decl *D, bool isParam,
2022
2016
continue ;
2023
2017
}
2024
2018
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
+
2025
2029
auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr);
2026
2030
if (!swiftAttr)
2027
2031
continue ;
@@ -2297,13 +2301,7 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2297
2301
2298
2302
static ImportTypeKind
2299
2303
getImportTypeKindForParam (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;
2307
2305
}
2308
2306
2309
2307
llvm::Optional<ClangImporter::Implementation::ImportParameterTypeResult>
0 commit comments