Skip to content

Commit 591c70e

Browse files
committed
Fix Crashes When Resolving Clang Types For Unrepresentable UnsafePointers
If the underlying pointer type was not representable in C, we would attempt to form a pointer type with a null underlying type and crash.
1 parent c2b13cd commit 591c70e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/AST/ClangTypeConverter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,10 @@ ClangTypeConverter::visitBoundGenericType(BoundGenericType *type) {
572572
return ClangASTContext.getPointerType(clangTy);
573573
}
574574
case StructKind::UnsafePointer: {
575-
return ClangASTContext.getPointerType(convert(argCanonicalTy).withConst());
575+
auto clangTy = convert(argCanonicalTy);
576+
if (clangTy.isNull())
577+
return clang::QualType();
578+
return ClangASTContext.getPointerType(clangTy.withConst());
576579
}
577580

578581
case StructKind::CFunctionPointer: {
@@ -592,6 +595,8 @@ ClangTypeConverter::visitBoundGenericType(BoundGenericType *type) {
592595

593596
case StructKind::SIMD: {
594597
clang::QualType scalarTy = convert(argCanonicalTy);
598+
if (scalarTy.isNull())
599+
return clang::QualType();
595600
auto numEltsString = swiftStructDecl->getName().str();
596601
numEltsString.consume_front("SIMD");
597602
unsigned numElts;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
3+
public typealias GUID = (a: UInt32, b: UInt16, c: UInt16, d: UInt8, e: UInt8, f: UInt8, g: UInt8, h: UInt8, i: UInt8, j: UInt8, k: UInt8)
4+
let function1: @convention(c) (UnsafePointer<GUID>) -> Void

0 commit comments

Comments
 (0)