Skip to content

Commit 7bcd13b

Browse files
committed
[cxx-interop] Avoid crashing when importing functions that take pointers to dependent types
Importing `type_traits` from libstdc++ currently causes a crash on Linux: ``` swift-ide-test: tools/clang/include/clang/AST/TypeNodes.inc:33: clang::TypeInfo clang::ASTContext::getTypeInfoImpl(const clang::Type *) const: Assertion `!T->isDependentType() && "should not see dependent types here"' failed. PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace. Stack dump: 0. Program arguments: /home/egorzh/Builds/swift/swift/bin/swift-ide-test -print-module -module-to-print=std -source-filename=x -enable-cxx-interop 1. /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:1110:10: importing 'std::__do_is_implicitly_default_constructible_impl' 2. /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:1116:22: importing 'std::__do_is_implicitly_default_constructible_impl::__test' ``` This change fixes the crash by bailing on such functions.
1 parent 0d87a10 commit 7bcd13b

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
@@ -454,6 +454,9 @@ namespace {
454454
ImportHint::OtherPointer};
455455
}
456456

457+
if (pointeeQualType->isDependentType())
458+
return Type();
459+
457460
// All other C pointers to concrete types map to
458461
// UnsafeMutablePointer<T> or OpaquePointer.
459462

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)