@@ -554,6 +554,8 @@ namespace {
554
554
if (auto wrapped = pointeeType->wrapInPointer (pointerKind)) {
555
555
return {wrapped, ImportHint::OtherPointer};
556
556
} else {
557
+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
558
+ pointerKind));
557
559
return Type ();
558
560
}
559
561
}
@@ -611,8 +613,11 @@ namespace {
611
613
pointerKind = PTK_UnsafeMutablePointer;
612
614
}
613
615
614
- return {pointeeType->wrapInPointer (pointerKind),
615
- ImportHint::None};
616
+ auto pointerType = pointeeType->wrapInPointer (pointerKind);
617
+ if (!pointerType)
618
+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
619
+ pointerKind));
620
+ return {pointerType, ImportHint::None};
616
621
}
617
622
618
623
ImportResult VisitMemberPointer (const clang::MemberPointerType *type) {
@@ -1414,7 +1419,8 @@ static Type maybeImportNSErrorOutParameter(ClangImporter::Implementation &impl,
1414
1419
1415
1420
static Type maybeImportCFOutParameter (ClangImporter::Implementation &impl,
1416
1421
Type importedType,
1417
- ImportTypeAttrs attrs) {
1422
+ ImportTypeAttrs attrs,
1423
+ llvm::function_ref<void (Diagnostic &&)> addImportDiagnostic) {
1418
1424
PointerTypeKind PTK;
1419
1425
auto elementType = importedType->getAnyPointerElementType (PTK);
1420
1426
if (!elementType || PTK != PTK_UnsafeMutablePointer)
@@ -1446,6 +1452,9 @@ static Type maybeImportCFOutParameter(ClangImporter::Implementation &impl,
1446
1452
pointerKind = PTK_AutoreleasingUnsafeMutablePointer;
1447
1453
1448
1454
resultTy = resultTy->wrapInPointer (pointerKind);
1455
+ if (!resultTy)
1456
+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
1457
+ pointerKind));
1449
1458
return resultTy;
1450
1459
}
1451
1460
@@ -1483,7 +1492,12 @@ static ImportedType adjustTypeForConcreteImport(
1483
1492
importKind != ImportTypeKind::Result) {
1484
1493
return {Type (), false };
1485
1494
}
1486
- importedType = impl.getNamedSwiftType (impl.getStdlibModule (), " Void" );
1495
+ importedType = impl.SwiftContext .getVoidType ();
1496
+ if (!importedType) {
1497
+ addImportDiagnostic (Diagnostic (diag::bridged_type_not_found_in_module,
1498
+ " Void" , " Swift" ));
1499
+ return {Type (), false };
1500
+ }
1487
1501
break ;
1488
1502
1489
1503
case ImportHint::ObjCBridged:
@@ -1599,7 +1613,8 @@ static ImportedType adjustTypeForConcreteImport(
1599
1613
if (attrs.contains (ImportTypeAttr::CFRetainedOutParameter) ||
1600
1614
attrs.contains (ImportTypeAttr::CFUnretainedOutParameter)) {
1601
1615
if (Type outParamTy =
1602
- maybeImportCFOutParameter (impl, importedType, attrs)) {
1616
+ maybeImportCFOutParameter (impl, importedType, attrs,
1617
+ addImportDiagnostic)) {
1603
1618
importedType = outParamTy;
1604
1619
break ;
1605
1620
}
@@ -2220,8 +2235,15 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
2220
2235
op == clang::OverloadedOperatorKind::OO_MinusEqual ||
2221
2236
op == clang::OverloadedOperatorKind::OO_StarEqual ||
2222
2237
op == clang::OverloadedOperatorKind::OO_SlashEqual) &&
2223
- clangDecl->getReturnType ()->isReferenceType ())
2224
- return {SwiftContext.getVoidType (), false };
2238
+ clangDecl->getReturnType ()->isReferenceType ()) {
2239
+ auto voidTy = SwiftContext.getVoidType ();
2240
+ if (!voidTy)
2241
+ addImportDiagnostic (clangDecl,
2242
+ Diagnostic (diag::bridged_type_not_found_in_module,
2243
+ " Void" , " Swift" ),
2244
+ clangDecl->getLocation ());
2245
+ return {voidTy, false };
2246
+ }
2225
2247
2226
2248
// Fix up optionality.
2227
2249
OptionalTypeKind OptionalityOfReturn;
@@ -2388,7 +2410,10 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2388
2410
auto genericType =
2389
2411
findGenericTypeInGenericDecls (*this , templateParamType, genericParams,
2390
2412
getImportTypeAttrs (clangDecl), addDiag);
2391
- importedType = {genericType->wrapInPointer (pointerKind), false };
2413
+ auto genericPointerType = genericType->wrapInPointer (pointerKind);
2414
+ if (!genericPointerType)
2415
+ addDiag (Diagnostic (diag::bridged_pointer_type_not_found, pointerKind));
2416
+ importedType = {genericPointerType, false };
2392
2417
} else if (!(isa<clang::RecordType>(returnType) ||
2393
2418
isa<clang::TemplateSpecializationType>(returnType)) ||
2394
2419
// TODO: we currently don't lazily load operator return types, but
@@ -2472,8 +2497,11 @@ ClangImporter::Implementation::importParameterType(
2472
2497
auto genericType = findGenericTypeInGenericDecls (
2473
2498
*this , templateParamType, genericParams, attrs, addImportDiagnosticFn);
2474
2499
swiftParamTy = genericType->wrapInPointer (pointerKind);
2475
- if (!swiftParamTy)
2500
+ if (!swiftParamTy) {
2501
+ addImportDiagnosticFn (Diagnostic (diag::bridged_pointer_type_not_found,
2502
+ pointerKind));
2476
2503
return std::nullopt;
2504
+ }
2477
2505
} else if (isa<clang::ReferenceType>(paramTy) &&
2478
2506
isa<clang::TemplateTypeParmType>(paramTy->getPointeeType ())) {
2479
2507
// We don't support universal reference, bail.
@@ -3515,6 +3543,11 @@ ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
3515
3543
3516
3544
*params = ParameterList::create (SwiftContext, paramInfo);
3517
3545
resultTy = SwiftContext.getVoidType ();
3546
+ if (!resultTy)
3547
+ addImportDiagnostic (clangDecl,
3548
+ Diagnostic (diag::bridged_type_not_found_in_module,
3549
+ " Void" , " Swift" ),
3550
+ clangDecl->getLocation ());
3518
3551
isIUO = false ;
3519
3552
}
3520
3553
0 commit comments