@@ -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
}
@@ -2216,8 +2231,15 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
2216
2231
op == clang::OverloadedOperatorKind::OO_MinusEqual ||
2217
2232
op == clang::OverloadedOperatorKind::OO_StarEqual ||
2218
2233
op == clang::OverloadedOperatorKind::OO_SlashEqual) &&
2219
- clangDecl->getReturnType ()->isReferenceType ())
2220
- return {SwiftContext.getVoidType (), false };
2234
+ clangDecl->getReturnType ()->isReferenceType ()) {
2235
+ auto voidTy = SwiftContext.getVoidType ();
2236
+ if (!voidTy)
2237
+ addImportDiagnostic (clangDecl,
2238
+ Diagnostic (diag::bridged_type_not_found_in_module,
2239
+ " Void" , " Swift" ),
2240
+ clangDecl->getLocation ());
2241
+ return {voidTy, false };
2242
+ }
2221
2243
2222
2244
// Fix up optionality.
2223
2245
OptionalTypeKind OptionalityOfReturn;
@@ -2384,7 +2406,10 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2384
2406
auto genericType =
2385
2407
findGenericTypeInGenericDecls (*this , templateParamType, genericParams,
2386
2408
getImportTypeAttrs (clangDecl), addDiag);
2387
- importedType = {genericType->wrapInPointer (pointerKind), false };
2409
+ auto genericPointerType = genericType->wrapInPointer (pointerKind);
2410
+ if (!genericPointerType)
2411
+ addDiag (Diagnostic (diag::bridged_pointer_type_not_found, pointerKind));
2412
+ importedType = {genericPointerType, false };
2388
2413
} else if (!(isa<clang::RecordType>(returnType) ||
2389
2414
isa<clang::TemplateSpecializationType>(returnType)) ||
2390
2415
// TODO: we currently don't lazily load operator return types, but
@@ -2468,8 +2493,11 @@ ClangImporter::Implementation::importParameterType(
2468
2493
auto genericType = findGenericTypeInGenericDecls (
2469
2494
*this , templateParamType, genericParams, attrs, addImportDiagnosticFn);
2470
2495
swiftParamTy = genericType->wrapInPointer (pointerKind);
2471
- if (!swiftParamTy)
2496
+ if (!swiftParamTy) {
2497
+ addImportDiagnosticFn (Diagnostic (diag::bridged_pointer_type_not_found,
2498
+ pointerKind));
2472
2499
return std::nullopt;
2500
+ }
2473
2501
} else if (isa<clang::ReferenceType>(paramTy) &&
2474
2502
isa<clang::TemplateTypeParmType>(paramTy->getPointeeType ())) {
2475
2503
// We don't support universal reference, bail.
@@ -3507,6 +3535,11 @@ ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
3507
3535
3508
3536
*params = ParameterList::create (SwiftContext, paramInfo);
3509
3537
resultTy = SwiftContext.getVoidType ();
3538
+ if (!resultTy)
3539
+ addImportDiagnostic (clangDecl,
3540
+ Diagnostic (diag::bridged_type_not_found_in_module,
3541
+ " Void" , " Swift" ),
3542
+ clangDecl->getLocation ());
3510
3543
isIUO = false ;
3511
3544
}
3512
3545
0 commit comments