@@ -554,6 +554,8 @@ namespace {
554554 if (auto wrapped = pointeeType->wrapInPointer (pointerKind)) {
555555 return {wrapped, ImportHint::OtherPointer};
556556 } else {
557+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
558+ pointerKind));
557559 return Type ();
558560 }
559561 }
@@ -611,8 +613,11 @@ namespace {
611613 pointerKind = PTK_UnsafeMutablePointer;
612614 }
613615
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};
616621 }
617622
618623 ImportResult VisitMemberPointer (const clang::MemberPointerType *type) {
@@ -1414,7 +1419,8 @@ static Type maybeImportNSErrorOutParameter(ClangImporter::Implementation &impl,
14141419
14151420static Type maybeImportCFOutParameter (ClangImporter::Implementation &impl,
14161421 Type importedType,
1417- ImportTypeAttrs attrs) {
1422+ ImportTypeAttrs attrs,
1423+ llvm::function_ref<void (Diagnostic &&)> addImportDiagnostic) {
14181424 PointerTypeKind PTK;
14191425 auto elementType = importedType->getAnyPointerElementType (PTK);
14201426 if (!elementType || PTK != PTK_UnsafeMutablePointer)
@@ -1446,6 +1452,9 @@ static Type maybeImportCFOutParameter(ClangImporter::Implementation &impl,
14461452 pointerKind = PTK_AutoreleasingUnsafeMutablePointer;
14471453
14481454 resultTy = resultTy->wrapInPointer (pointerKind);
1455+ if (!resultTy)
1456+ addImportDiagnostic (Diagnostic (diag::bridged_pointer_type_not_found,
1457+ pointerKind));
14491458 return resultTy;
14501459}
14511460
@@ -1483,7 +1492,12 @@ static ImportedType adjustTypeForConcreteImport(
14831492 importKind != ImportTypeKind::Result) {
14841493 return {Type (), false };
14851494 }
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+ }
14871501 break ;
14881502
14891503 case ImportHint::ObjCBridged:
@@ -1599,7 +1613,8 @@ static ImportedType adjustTypeForConcreteImport(
15991613 if (attrs.contains (ImportTypeAttr::CFRetainedOutParameter) ||
16001614 attrs.contains (ImportTypeAttr::CFUnretainedOutParameter)) {
16011615 if (Type outParamTy =
1602- maybeImportCFOutParameter (impl, importedType, attrs)) {
1616+ maybeImportCFOutParameter (impl, importedType, attrs,
1617+ addImportDiagnostic)) {
16031618 importedType = outParamTy;
16041619 break ;
16051620 }
@@ -2216,8 +2231,15 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
22162231 op == clang::OverloadedOperatorKind::OO_MinusEqual ||
22172232 op == clang::OverloadedOperatorKind::OO_StarEqual ||
22182233 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+ }
22212243
22222244 // Fix up optionality.
22232245 OptionalTypeKind OptionalityOfReturn;
@@ -2384,7 +2406,10 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
23842406 auto genericType =
23852407 findGenericTypeInGenericDecls (*this , templateParamType, genericParams,
23862408 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 };
23882413 } else if (!(isa<clang::RecordType>(returnType) ||
23892414 isa<clang::TemplateSpecializationType>(returnType)) ||
23902415 // TODO: we currently don't lazily load operator return types, but
@@ -2468,8 +2493,11 @@ ClangImporter::Implementation::importParameterType(
24682493 auto genericType = findGenericTypeInGenericDecls (
24692494 *this , templateParamType, genericParams, attrs, addImportDiagnosticFn);
24702495 swiftParamTy = genericType->wrapInPointer (pointerKind);
2471- if (!swiftParamTy)
2496+ if (!swiftParamTy) {
2497+ addImportDiagnosticFn (Diagnostic (diag::bridged_pointer_type_not_found,
2498+ pointerKind));
24722499 return std::nullopt ;
2500+ }
24732501 } else if (isa<clang::ReferenceType>(paramTy) &&
24742502 isa<clang::TemplateTypeParmType>(paramTy->getPointeeType ())) {
24752503 // We don't support universal reference, bail.
@@ -3507,6 +3535,11 @@ ImportedType ClangImporter::Implementation::importAccessorParamsAndReturnType(
35073535
35083536 *params = ParameterList::create (SwiftContext, paramInfo);
35093537 resultTy = SwiftContext.getVoidType ();
3538+ if (!resultTy)
3539+ addImportDiagnostic (clangDecl,
3540+ Diagnostic (diag::bridged_type_not_found_in_module,
3541+ " Void" , " Swift" ),
3542+ clangDecl->getLocation ());
35103543 isIUO = false ;
35113544 }
35123545
0 commit comments