Skip to content

Commit 687beac

Browse files
authored
Merge pull request #41894 from apple/egorzhdan/cxx-decltype-crash
[cxx-interop] Avoid crashing when importing functions that take pointers to dependent types
2 parents 9b9888c + 7bcd13b commit 687beac

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ namespace {
460460
ImportHint::OtherPointer};
461461
}
462462

463+
if (pointeeQualType->isDependentType())
464+
return Type();
465+
463466
// All other C pointers to concrete types map to
464467
// UnsafeMutablePointer<T> or OpaquePointer.
465468

test/Interop/Cxx/templates/Inputs/function-templates.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ decltype(auto) testAuto(T arg) {
4444
return arg;
4545
}
4646

47+
template <typename T>
48+
struct ClassTemplate {
49+
T t;
50+
};
51+
52+
template <typename T>
53+
void takesPointerToDependent(ClassTemplate<T> *ct) {
54+
ct->t++;
55+
}
56+
57+
template <typename T>
58+
T usedInDeclType(T) {}
59+
60+
template <typename T>
61+
void takesDeclTypePointer(decltype(usedInDeclType<T>()) *) {}
62+
4763
// TODO: Add tests for Decltype, UnaryTransform, and TemplateSpecialization with
4864
// a dependent type once those are supported.
4965

test/Interop/Cxx/templates/defaulted-template-type-parameter-module-interface.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// CHECK: func defaultedTemplateReferenceTypeParam<T>(_ t: inout T)
1818
// The following types aren't imported correctly, but that does not have to do
1919
// with the fact that the template type paramaters are defaulted.
20-
// CHECK: func defaultedTemplatePointerTypeParam<T>(_ t: UnsafeMutablePointer<T>)
21-
// CHECK: func defaultedTemplatePointerReferenceTypeParam<T>(_ t: inout OpaquePointer!)
22-
// CHECK: func defaultedTemplatePointerPointerTypeParam<T>(_ t: UnsafeMutablePointer<OpaquePointer?>!)
20+
// TODO: reenable the following checks: (rdar://90587703)
21+
// TODO-CHECK: func defaultedTemplatePointerTypeParam<T>(_ t: UnsafeMutablePointer<T>)
22+
// TODO-CHECK: func defaultedTemplatePointerReferenceTypeParam<T>(_ t: inout OpaquePointer!)
23+
// TODO-CHECK: func defaultedTemplatePointerPointerTypeParam<T>(_ t: UnsafeMutablePointer<OpaquePointer?>!)

test/Interop/Cxx/templates/function-template-module-interface.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
// CHECK: mutating func test2(_: Int32, _ varargs: Any...)
1515
// CHECK: }
1616

17+
// TODO: import functions that take a pointer to a dependent type (rdar://90587703).
18+
// CHECK-NOT: func takesPointerToDependent
19+
// CHECK-NOT: func takesDeclTypePointer
20+
1721
// CHECK: func lvalueReference<T>(_ ref: inout T)
1822
// CHECK: func constLvalueReference<T>(_: T)
1923
// CHECK: func forwardingReference<T>(_: inout T)

0 commit comments

Comments
 (0)