Skip to content

Commit 785288b

Browse files
authored
Merge pull request #36967 from nkcsgexi/72164992-5.5
[5.5] ClangImporter: add some error-recovery code path for TypeBase::wrapInPointer
2 parents 7253dae + 1a183e4 commit 785288b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/AST/Type.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ Type TypeBase::wrapInPointer(PointerTypeKind kind) {
689689
switch (kind) {
690690
case PTK_UnsafeMutableRawPointer:
691691
case PTK_UnsafeRawPointer:
692-
llvm_unreachable("these pointer types don't take arguments");
692+
// these pointer types don't take arguments.
693+
return (NominalTypeDecl*)nullptr;
693694
case PTK_UnsafePointer:
694695
return ctx.getUnsafePointerDecl();
695696
case PTK_UnsafeMutablePointer:
@@ -701,6 +702,10 @@ Type TypeBase::wrapInPointer(PointerTypeKind kind) {
701702
}());
702703

703704
assert(pointerDecl);
705+
// Don't fail hard on null pointerDecl.
706+
if (!pointerDecl) {
707+
return Type();
708+
}
704709
return BoundGenericType::get(pointerDecl, /*parent*/nullptr, Type(this));
705710
}
706711

lib/ClangImporter/ImportType.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,11 @@ namespace {
487487
pointerKind = PTK_UnsafeMutablePointer;
488488
}
489489
}
490-
491-
return {pointeeType->wrapInPointer(pointerKind),
492-
ImportHint::OtherPointer};
490+
if (auto wrapped = pointeeType->wrapInPointer(pointerKind)) {
491+
return {wrapped, ImportHint::OtherPointer};
492+
} else {
493+
return Type();
494+
}
493495
}
494496

495497
ImportResult VisitBlockPointerType(const clang::BlockPointerType *type) {
@@ -1926,6 +1928,8 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
19261928
auto genericType =
19271929
findGenericTypeInGenericDecls(templateParamType, genericParams);
19281930
swiftParamTy = genericType->wrapInPointer(pointerKind);
1931+
if (!swiftParamTy)
1932+
return nullptr;
19291933
} else if (auto *templateParamType =
19301934
dyn_cast<clang::TemplateTypeParmType>(paramTy)) {
19311935
swiftParamTy =

0 commit comments

Comments
 (0)