Skip to content

Commit 86886d9

Browse files
committed
[cxx-interop] do not rely on bodyParams being always non-null when importing function's name
This change fixes a swift-ide-test crash that occured in the Interop\Cxx\stdlib\msvcprt-module-interface.swift testcase with a newer MSVC, as one of its operator() had a parameter with a type that couldn't have been imported. The change ensures that body params are not used if they're null.
1 parent fc52f2f commit 86886d9

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,20 +3621,20 @@ namespace {
36213621
}
36223622
}
36233623

3624-
if (name && name.isSimpleName()) {
3625-
assert(importedName.hasCustomName() &&
3626-
"imported function with simple name?");
3627-
// Just fill in empty argument labels.
3628-
name = DeclName(Impl.SwiftContext, name.getBaseName(), bodyParams);
3629-
}
3630-
36313624
if (!bodyParams) {
36323625
Impl.addImportDiagnostic(
36333626
decl, Diagnostic(diag::invoked_func_not_imported, decl),
36343627
decl->getSourceRange().getBegin());
36353628
return nullptr;
36363629
}
36373630

3631+
if (name && name.isSimpleName()) {
3632+
assert(importedName.hasCustomName() &&
3633+
"imported function with simple name?");
3634+
// Just fill in empty argument labels.
3635+
name = DeclName(Impl.SwiftContext, name.getBaseName(), bodyParams);
3636+
}
3637+
36383638
if (name && name.getArgumentNames().size() != bodyParams->size()) {
36393639
// We synthesized additional parameters so rebuild the DeclName.
36403640
name = DeclName(Impl.SwiftContext, name.getBaseName(), bodyParams);

test/Interop/Cxx/operators/Inputs/member-inline.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,23 @@ class HasStaticOperatorCallWithConstOperator {
501501
}
502502
};
503503

504+
505+
// This type is intentionally unimportable,
506+
// to ensure that the function that uses in a parameter
507+
// cannot import its parameter list.
508+
struct UnimportableCxxTypeByDefault {
509+
private:
510+
UnimportableCxxTypeByDefault(const UnimportableCxxTypeByDefault &) = delete;
511+
UnimportableCxxTypeByDefault(UnimportableCxxTypeByDefault &&) = delete;
512+
};
513+
514+
struct HasStaticOperatorCallWithUnimportableCxxType {
515+
// This operator won't be imported.
516+
static int operator()(const UnimportableCxxTypeByDefault &) noexcept {
517+
return 0;
518+
}
519+
};
520+
504521
struct ClassWithOperatorStarAvailable {
505522
int value;
506523

test/Interop/Cxx/operators/member-inline-module-interface.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,7 @@
307307
// CHECK: func callAsFunction(_ x: Int32, _ y: Int32) -> Int32
308308
// CHECK: func callAsFunction(_ x: Int32) -> Int32
309309
// CHECK: }
310+
311+
// CHECK: struct HasStaticOperatorCallWithUnimportableCxxType {
312+
// CHECK-NEXT: init()
313+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)