@@ -531,6 +531,8 @@ namespace {
531
531
if (auto wrapped = pointeeType->wrapInPointer (pointerKind)) {
532
532
return {wrapped, ImportHint::OtherPointer};
533
533
} else {
534
+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
535
+ pointerKind));
534
536
return Type ();
535
537
}
536
538
}
@@ -588,8 +590,11 @@ namespace {
588
590
pointerKind = PTK_UnsafeMutablePointer;
589
591
}
590
592
591
- return {pointeeType->wrapInPointer (pointerKind),
592
- ImportHint::None};
593
+ auto pointerType = pointeeType->wrapInPointer (pointerKind);
594
+ if (!pointerType)
595
+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
596
+ pointerKind));
597
+ return {pointerType, ImportHint::None};
593
598
}
594
599
595
600
ImportResult VisitMemberPointer (const clang::MemberPointerType *type) {
@@ -1381,7 +1386,8 @@ static Type maybeImportNSErrorOutParameter(ClangImporter::Implementation &impl,
1381
1386
1382
1387
static Type maybeImportCFOutParameter (ClangImporter::Implementation &impl,
1383
1388
Type importedType,
1384
- ImportTypeAttrs attrs) {
1389
+ ImportTypeAttrs attrs,
1390
+ llvm::function_ref<void (Diagnostic &&)> addImportDiagnostic) {
1385
1391
PointerTypeKind PTK;
1386
1392
auto elementType = importedType->getAnyPointerElementType (PTK);
1387
1393
if (!elementType || PTK != PTK_UnsafeMutablePointer)
@@ -1413,6 +1419,9 @@ static Type maybeImportCFOutParameter(ClangImporter::Implementation &impl,
1413
1419
pointerKind = PTK_AutoreleasingUnsafeMutablePointer;
1414
1420
1415
1421
resultTy = resultTy->wrapInPointer (pointerKind);
1422
+ if (!resultTy)
1423
+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
1424
+ pointerKind));
1416
1425
return resultTy;
1417
1426
}
1418
1427
@@ -1450,7 +1459,12 @@ static ImportedType adjustTypeForConcreteImport(
1450
1459
importKind != ImportTypeKind::Result) {
1451
1460
return {Type (), false };
1452
1461
}
1453
- importedType = impl.getNamedSwiftType (impl.getStdlibModule (), " Void" );
1462
+ importedType = impl.SwiftContext .getVoidType ();
1463
+ if (!importedType) {
1464
+ addImportDiagnostic (Diagnostic (diag::bridged_type_not_found_in_module,
1465
+ " Void" , " Swift" ));
1466
+ return {Type (), false };
1467
+ }
1454
1468
break ;
1455
1469
1456
1470
case ImportHint::ObjCBridged:
@@ -1566,7 +1580,8 @@ static ImportedType adjustTypeForConcreteImport(
1566
1580
if (attrs.contains (ImportTypeAttr::CFRetainedOutParameter) ||
1567
1581
attrs.contains (ImportTypeAttr::CFUnretainedOutParameter)) {
1568
1582
if (Type outParamTy =
1569
- maybeImportCFOutParameter (impl, importedType, attrs)) {
1583
+ maybeImportCFOutParameter (impl, importedType, attrs,
1584
+ addImportDiagnostic)) {
1570
1585
importedType = outParamTy;
1571
1586
break ;
1572
1587
}
@@ -2183,8 +2198,15 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
2183
2198
op == clang::OverloadedOperatorKind::OO_MinusEqual ||
2184
2199
op == clang::OverloadedOperatorKind::OO_StarEqual ||
2185
2200
op == clang::OverloadedOperatorKind::OO_SlashEqual) &&
2186
- clangDecl->getReturnType ()->isReferenceType ())
2187
- return {SwiftContext.getVoidType (), false };
2201
+ clangDecl->getReturnType ()->isReferenceType ()) {
2202
+ auto voidTy = SwiftContext.getVoidType ();
2203
+ if (!voidTy)
2204
+ addImportDiagnostic (clangDecl,
2205
+ Diagnostic (diag::bridged_type_not_found_in_module,
2206
+ " Void" , " Swift" ),
2207
+ clangDecl->getLocation ());
2208
+ return {voidTy, false };
2209
+ }
2188
2210
2189
2211
// Fix up optionality.
2190
2212
OptionalTypeKind OptionalityOfReturn;
@@ -2351,7 +2373,10 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2351
2373
auto genericType =
2352
2374
findGenericTypeInGenericDecls (*this , templateParamType, genericParams,
2353
2375
getImportTypeAttrs (clangDecl), addDiag);
2354
- importedType = {genericType->wrapInPointer (pointerKind), false };
2376
+ auto genericPointerType = genericType->wrapInPointer (pointerKind);
2377
+ if (!genericPointerType)
2378
+ addDiag (Diagnostic (diag::bridged_pointer_type_not_found, pointerKind));
2379
+ importedType = {genericPointerType, false };
2355
2380
} else if (!(isa<clang::RecordType>(returnType) ||
2356
2381
isa<clang::TemplateSpecializationType>(returnType)) ||
2357
2382
// TODO: we currently don't lazily load operator return types, but
@@ -2434,8 +2459,11 @@ ClangImporter::Implementation::importParameterType(
2434
2459
auto genericType = findGenericTypeInGenericDecls (
2435
2460
*this , templateParamType, genericParams, attrs, addImportDiagnosticFn);
2436
2461
swiftParamTy = genericType->wrapInPointer (pointerKind);
2437
- if (!swiftParamTy)
2462
+ if (!swiftParamTy) {
2463
+ addImportDiagnosticFn (Diagnostic (diag::bridged_pointer_type_not_found,
2464
+ pointerKind));
2438
2465
return std::nullopt;
2466
+ }
2439
2467
} else if (isa<clang::ReferenceType>(paramTy) &&
2440
2468
isa<clang::TemplateTypeParmType>(paramTy->getPointeeType ())) {
2441
2469
// We don't support rvalue reference / universal perfect ref, bail.
@@ -3466,6 +3494,11 @@ ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
3466
3494
3467
3495
*params = ParameterList::create (SwiftContext, paramInfo);
3468
3496
resultTy = SwiftContext.getVoidType ();
3497
+ if (!resultTy)
3498
+ addImportDiagnostic (clangDecl,
3499
+ Diagnostic (diag::bridged_type_not_found_in_module,
3500
+ " Void" , " Swift" ),
3501
+ clangDecl->getLocation ());
3469
3502
isIUO = false ;
3470
3503
}
3471
3504
0 commit comments