Skip to content

Commit b681b0a

Browse files
authored
Merge pull request #41810 from zoecarver/fix-crash-ref-to-depentent-param
2 parents 0d100e6 + 16c8d0b commit b681b0a

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,14 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
22112211
findGenericTypeInGenericDecls(templateParamType, genericParams);
22122212
} else {
22132213
if (auto refType = dyn_cast<clang::ReferenceType>(paramTy)) {
2214+
// We don't support reference type to a dependent type, just bail.
2215+
if (refType->getPointeeType()->isDependentType()) {
2216+
addImportDiagnostic(
2217+
param, Diagnostic(diag::parameter_type_not_imported, param),
2218+
param->getSourceRange().getBegin());
2219+
return nullptr;
2220+
}
2221+
22142222
paramTy = refType->getPointeeType();
22152223
if (!paramTy.isConstQualified())
22162224
isInOut = true;

test/Interop/Cxx/reference/Inputs/reference.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ T &refToTemplate(T &t) { return t; }
3434
template<class T>
3535
const T &constRefToTemplate(const T &t) { return t; }
3636

37+
template<class T>
38+
void refToDependentParam(ClassTemplate<T> &param) { }
39+
3740
#endif // TEST_INTEROP_CXX_REFERENCE_INPUTS_REFERENCE_H

test/Interop/Cxx/reference/reference-module-interface.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
// CHECK: func constRefToTemplate<T>(_ t: T) -> UnsafePointer<T>
1717

1818
// CHECK-NOT: refToDependent
19+
// CHECK-NOT: refToDependentParam
1920
// CHECK-NOT: dontImportAtomicRef

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
// with the fact that the template type paramaters are defaulted.
2020
// TODO: reenable the following checks: (rdar://90587703)
2121
// TODO-CHECK: func defaultedTemplatePointerTypeParam<T>(_ t: UnsafeMutablePointer<T>)
22-
// TODO-CHECK: func defaultedTemplatePointerReferenceTypeParam<T>(_ t: inout OpaquePointer!)
2322
// TODO-CHECK: func defaultedTemplatePointerPointerTypeParam<T>(_ t: UnsafeMutablePointer<OpaquePointer?>!)
23+
24+
// CHECK: func defaultedTemplatePointerTypeParam<T>(_ t: UnsafeMutablePointer<T>)
25+
// We don't support references to dependent types (rdar://89034440).
26+
// CHECK-NOT: defaultedTemplatePointerReferenceTypeParam

test/Interop/Cxx/templates/dependent-types-module-interface.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
// CHECK: func multipleDependentArgsInferred<T, U>(_ a: Any, _ b: Any, _ c: T, _ d: U) -> Any
88
// CHECK: func multipleDependentArgs<T, U>(_ a: Any, _ b: Any, T: T.Type, U: U.Type) -> Any
99
// CHECK: func refToDependent<T>(_ a: inout T) -> Any
10-
// CHECK: func dependentRef<T>(_ a: inout Any, T: T.Type) -> Any
11-
// CHECK: func dependentRefAndRefInferred<T>(_ a: Any, _ b: inout T) -> Any
10+
// We don't support references to dependent types (rdar://89034440).
11+
// CHECK-NOT: dependentRef
12+
// CHECK-NOT: dependentRefAndRefInferred

0 commit comments

Comments
 (0)