@@ -558,6 +558,8 @@ namespace {
558
558
if (auto wrapped = pointeeType->wrapInPointer (pointerKind)) {
559
559
return {wrapped, ImportHint::OtherPointer};
560
560
} else {
561
+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
562
+ pointerKind));
561
563
return Type ();
562
564
}
563
565
}
@@ -615,8 +617,11 @@ namespace {
615
617
pointerKind = PTK_UnsafeMutablePointer;
616
618
}
617
619
618
- return {pointeeType->wrapInPointer (pointerKind),
619
- ImportHint::None};
620
+ auto pointerType = pointeeType->wrapInPointer (pointerKind);
621
+ if (!pointerType)
622
+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
623
+ pointerKind));
624
+ return {pointerType, ImportHint::None};
620
625
}
621
626
622
627
ImportResult VisitMemberPointer (const clang::MemberPointerType *type) {
@@ -1405,7 +1410,8 @@ static Type maybeImportNSErrorOutParameter(ClangImporter::Implementation &impl,
1405
1410
1406
1411
static Type maybeImportCFOutParameter (ClangImporter::Implementation &impl,
1407
1412
Type importedType,
1408
- ImportTypeAttrs attrs) {
1413
+ ImportTypeAttrs attrs,
1414
+ llvm::function_ref<void (Diagnostic &&)> addImportDiagnostic) {
1409
1415
PointerTypeKind PTK;
1410
1416
auto elementType = importedType->getAnyPointerElementType (PTK);
1411
1417
if (!elementType || PTK != PTK_UnsafeMutablePointer)
@@ -1437,6 +1443,9 @@ static Type maybeImportCFOutParameter(ClangImporter::Implementation &impl,
1437
1443
pointerKind = PTK_AutoreleasingUnsafeMutablePointer;
1438
1444
1439
1445
resultTy = resultTy->wrapInPointer (pointerKind);
1446
+ if (!resultTy)
1447
+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
1448
+ pointerKind));
1440
1449
return resultTy;
1441
1450
}
1442
1451
@@ -1474,7 +1483,12 @@ static ImportedType adjustTypeForConcreteImport(
1474
1483
importKind != ImportTypeKind::Result) {
1475
1484
return {Type (), false };
1476
1485
}
1477
- importedType = impl.getNamedSwiftType (impl.getStdlibModule (), " Void" );
1486
+ importedType = impl.SwiftContext .getVoidType ();
1487
+ if (!importedType) {
1488
+ addImportDiagnostic (Diagnostic (diag::bridged_type_not_found_in_module,
1489
+ " Void" , " Swift" ));
1490
+ return {Type (), false };
1491
+ }
1478
1492
break ;
1479
1493
1480
1494
case ImportHint::ObjCBridged:
@@ -1590,7 +1604,8 @@ static ImportedType adjustTypeForConcreteImport(
1590
1604
if (attrs.contains (ImportTypeAttr::CFRetainedOutParameter) ||
1591
1605
attrs.contains (ImportTypeAttr::CFUnretainedOutParameter)) {
1592
1606
if (Type outParamTy =
1593
- maybeImportCFOutParameter (impl, importedType, attrs)) {
1607
+ maybeImportCFOutParameter (impl, importedType, attrs,
1608
+ addImportDiagnostic)) {
1594
1609
importedType = outParamTy;
1595
1610
break ;
1596
1611
}
@@ -2206,8 +2221,15 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
2206
2221
if (op == clang::OverloadedOperatorKind::OO_PlusEqual ||
2207
2222
op == clang::OverloadedOperatorKind::OO_MinusEqual ||
2208
2223
op == clang::OverloadedOperatorKind::OO_StarEqual ||
2209
- op == clang::OverloadedOperatorKind::OO_SlashEqual)
2210
- return {SwiftContext.getVoidType (), false };
2224
+ op == clang::OverloadedOperatorKind::OO_SlashEqual) {
2225
+ auto voidTy = SwiftContext.getVoidType ();
2226
+ if (!voidTy)
2227
+ addImportDiagnostic (clangDecl,
2228
+ Diagnostic (diag::bridged_type_not_found_in_module,
2229
+ " Void" , " Swift" ),
2230
+ clangDecl->getLocation ());
2231
+ return {voidTy, false };
2232
+ }
2211
2233
2212
2234
// Fix up optionality.
2213
2235
OptionalTypeKind OptionalityOfReturn;
@@ -2374,7 +2396,10 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2374
2396
auto genericType =
2375
2397
findGenericTypeInGenericDecls (*this , templateParamType, genericParams,
2376
2398
getImportTypeAttrs (clangDecl), addDiag);
2377
- importedType = {genericType->wrapInPointer (pointerKind), false };
2399
+ auto genericPointerType = genericType->wrapInPointer (pointerKind);
2400
+ if (!genericPointerType)
2401
+ addDiag (Diagnostic (diag::bridged_pointer_type_not_found, pointerKind));
2402
+ importedType = {genericPointerType, false };
2378
2403
} else if (!(isa<clang::RecordType>(returnType) ||
2379
2404
isa<clang::TemplateSpecializationType>(returnType)) ||
2380
2405
// TODO: we currently don't lazily load operator return types, but
@@ -2457,8 +2482,11 @@ ClangImporter::Implementation::importParameterType(
2457
2482
auto genericType = findGenericTypeInGenericDecls (
2458
2483
*this , templateParamType, genericParams, attrs, addImportDiagnosticFn);
2459
2484
swiftParamTy = genericType->wrapInPointer (pointerKind);
2460
- if (!swiftParamTy)
2485
+ if (!swiftParamTy) {
2486
+ addImportDiagnosticFn (Diagnostic (diag::bridged_pointer_type_not_found,
2487
+ pointerKind));
2461
2488
return std::nullopt;
2489
+ }
2462
2490
} else if (isa<clang::ReferenceType>(paramTy) &&
2463
2491
isa<clang::TemplateTypeParmType>(paramTy->getPointeeType ())) {
2464
2492
// We don't support rvalue reference / universal perfect ref, bail.
@@ -3481,6 +3509,11 @@ ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
3481
3509
3482
3510
*params = ParameterList::create (SwiftContext, paramInfo);
3483
3511
resultTy = SwiftContext.getVoidType ();
3512
+ if (!resultTy)
3513
+ addImportDiagnostic (clangDecl,
3514
+ Diagnostic (diag::bridged_type_not_found_in_module,
3515
+ " Void" , " Swift" ),
3516
+ clangDecl->getLocation ());
3484
3517
isIUO = false ;
3485
3518
}
3486
3519
0 commit comments