@@ -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) {
@@ -1382,7 +1387,8 @@ static Type maybeImportNSErrorOutParameter(ClangImporter::Implementation &impl,
1382
1387
1383
1388
static Type maybeImportCFOutParameter (ClangImporter::Implementation &impl,
1384
1389
Type importedType,
1385
- ImportTypeAttrs attrs) {
1390
+ ImportTypeAttrs attrs,
1391
+ llvm::function_ref<void (Diagnostic &&)> addImportDiagnostic) {
1386
1392
PointerTypeKind PTK;
1387
1393
auto elementType = importedType->getAnyPointerElementType (PTK);
1388
1394
if (!elementType || PTK != PTK_UnsafeMutablePointer)
@@ -1414,6 +1420,9 @@ static Type maybeImportCFOutParameter(ClangImporter::Implementation &impl,
1414
1420
pointerKind = PTK_AutoreleasingUnsafeMutablePointer;
1415
1421
1416
1422
resultTy = resultTy->wrapInPointer (pointerKind);
1423
+ if (!resultTy)
1424
+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
1425
+ pointerKind));
1417
1426
return resultTy;
1418
1427
}
1419
1428
@@ -1451,7 +1460,12 @@ static ImportedType adjustTypeForConcreteImport(
1451
1460
importKind != ImportTypeKind::Result) {
1452
1461
return {Type (), false };
1453
1462
}
1454
- importedType = impl.getNamedSwiftType (impl.getStdlibModule (), " Void" );
1463
+ importedType = impl.SwiftContext .getVoidType ();
1464
+ if (!importedType) {
1465
+ addImportDiagnostic (Diagnostic (diag::bridged_type_not_found_in_module,
1466
+ " Void" , " Swift" ));
1467
+ return {Type (), false };
1468
+ }
1455
1469
break ;
1456
1470
1457
1471
case ImportHint::ObjCBridged:
@@ -1567,7 +1581,8 @@ static ImportedType adjustTypeForConcreteImport(
1567
1581
if (attrs.contains (ImportTypeAttr::CFRetainedOutParameter) ||
1568
1582
attrs.contains (ImportTypeAttr::CFUnretainedOutParameter)) {
1569
1583
if (Type outParamTy =
1570
- maybeImportCFOutParameter (impl, importedType, attrs)) {
1584
+ maybeImportCFOutParameter (impl, importedType, attrs,
1585
+ addImportDiagnostic)) {
1571
1586
importedType = outParamTy;
1572
1587
break ;
1573
1588
}
@@ -2184,8 +2199,15 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
2184
2199
op == clang::OverloadedOperatorKind::OO_MinusEqual ||
2185
2200
op == clang::OverloadedOperatorKind::OO_StarEqual ||
2186
2201
op == clang::OverloadedOperatorKind::OO_SlashEqual) &&
2187
- clangDecl->getReturnType ()->isReferenceType ())
2188
- return {SwiftContext.getVoidType (), false };
2202
+ clangDecl->getReturnType ()->isReferenceType ()) {
2203
+ auto voidTy = SwiftContext.getVoidType ();
2204
+ if (!voidTy)
2205
+ addImportDiagnostic (clangDecl,
2206
+ Diagnostic (diag::bridged_type_not_found_in_module,
2207
+ " Void" , " Swift" ),
2208
+ clangDecl->getLocation ());
2209
+ return {voidTy, false };
2210
+ }
2189
2211
2190
2212
// Fix up optionality.
2191
2213
OptionalTypeKind OptionalityOfReturn;
@@ -2352,7 +2374,10 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2352
2374
auto genericType =
2353
2375
findGenericTypeInGenericDecls (*this , templateParamType, genericParams,
2354
2376
getImportTypeAttrs (clangDecl), addDiag);
2355
- importedType = {genericType->wrapInPointer (pointerKind), false };
2377
+ auto genericPointerType = genericType->wrapInPointer (pointerKind);
2378
+ if (!genericPointerType)
2379
+ addDiag (Diagnostic (diag::bridged_pointer_type_not_found, pointerKind));
2380
+ importedType = {genericPointerType, false };
2356
2381
} else if (!(isa<clang::RecordType>(returnType) ||
2357
2382
isa<clang::TemplateSpecializationType>(returnType)) ||
2358
2383
// TODO: we currently don't lazily load operator return types, but
@@ -2435,8 +2460,11 @@ ClangImporter::Implementation::importParameterType(
2435
2460
auto genericType = findGenericTypeInGenericDecls (
2436
2461
*this , templateParamType, genericParams, attrs, addImportDiagnosticFn);
2437
2462
swiftParamTy = genericType->wrapInPointer (pointerKind);
2438
- if (!swiftParamTy)
2463
+ if (!swiftParamTy) {
2464
+ addImportDiagnosticFn (Diagnostic (diag::bridged_pointer_type_not_found,
2465
+ pointerKind));
2439
2466
return std::nullopt;
2467
+ }
2440
2468
} else if (isa<clang::ReferenceType>(paramTy) &&
2441
2469
isa<clang::TemplateTypeParmType>(paramTy->getPointeeType ())) {
2442
2470
// We don't support rvalue reference / universal perfect ref, bail.
@@ -3459,6 +3487,11 @@ ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
3459
3487
3460
3488
*params = ParameterList::create (SwiftContext, paramInfo);
3461
3489
resultTy = SwiftContext.getVoidType ();
3490
+ if (!resultTy)
3491
+ addImportDiagnostic (clangDecl,
3492
+ Diagnostic (diag::bridged_type_not_found_in_module,
3493
+ " Void" , " Swift" ),
3494
+ clangDecl->getLocation ());
3462
3495
isIUO = false ;
3463
3496
}
3464
3497
0 commit comments