Skip to content

Commit 4364af3

Browse files
committed
[cxx-interop] Small fixes and cleanup based on review.
* Check isAggregate instead of hasUserDeclaredConstructor. * Rename addEmptyArgNamesForCxxFunc -> addEmptyArgNamesForClangFunction. * Other minor fixes and cleanups.
1 parent f04de9f commit 4364af3

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3452,10 +3452,8 @@ namespace {
34523452
ctors.push_back(createDefaultConstructor(Impl, result));
34533453
}
34543454

3455-
bool hasUserDeclaredConstructor =
3456-
cxxRecordDecl && cxxRecordDecl->hasUserDeclaredConstructor();
3457-
if (hasReferenceableFields && hasMemberwiseInitializer &&
3458-
!hasUserDeclaredConstructor) {
3455+
bool isAggregate = cxxRecordDecl && cxxRecordDecl->isAggregate();
3456+
if (hasReferenceableFields && hasMemberwiseInitializer && isAggregate) {
34593457
// The default zero initializer suppresses the implicit value
34603458
// constructor that would normally be formed, so we have to add that
34613459
// explicitly as well.

lib/ClangImporter/ImportName.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,11 +1367,10 @@ static bool suppressFactoryMethodAsInit(const clang::ObjCMethodDecl *method,
13671367
}
13681368

13691369
static void
1370-
addEmptyArgNamesForCxxFunc(const clang::FunctionDecl *funcDecl,
1371-
SmallVectorImpl<StringRef> &argumentNames) {
1372-
for (size_t i = 0; i < funcDecl->param_size(); ++i) {
1370+
addEmptyArgNamesForClangFunction(const clang::FunctionDecl *funcDecl,
1371+
SmallVectorImpl<StringRef> &argumentNames) {
1372+
for (size_t i = 0; i < funcDecl->param_size(); ++i)
13731373
argumentNames.push_back(StringRef());
1374-
}
13751374
if (funcDecl->isVariadic())
13761375
argumentNames.push_back(StringRef());
13771376
}
@@ -1614,9 +1613,8 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
16141613
isFunction = true;
16151614
result.info.initKind = CtorInitializerKind::Designated;
16161615
baseName = "init";
1617-
if (auto ctor = dyn_cast<clang::CXXConstructorDecl>(D)) {
1618-
addEmptyArgNamesForCxxFunc(ctor, argumentNames);
1619-
}
1616+
addEmptyArgNamesForClangFunction(cast<clang::CXXConstructorDecl>(D),
1617+
argumentNames);
16201618
break;
16211619

16221620
case clang::DeclarationName::CXXConversionFunctionName:
@@ -1691,7 +1689,7 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
16911689

16921690
if (auto function = dyn_cast<clang::FunctionDecl>(D)) {
16931691
isFunction = true;
1694-
addEmptyArgNamesForCxxFunc(function, argumentNames);
1692+
addEmptyArgNamesForClangFunction(function, argumentNames);
16951693
}
16961694
break;
16971695

test/Interop/Cxx/class/constructors-module-interface.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// CHECK-NEXT: }
1717
// CHECK-NEXT: struct DefaultConstructorDeleted {
1818
// CHECK-NEXT: var a: UnsafeMutablePointer<Int32>
19+
// CHECK-NEXT: init(a: UnsafeMutablePointer<Int32>)
1920
// CHECK-NEXT: }
2021
// CHECK-NEXT: struct ConstructorWithParam {
2122
// CHECK-NEXT: var x: Int32

test/Interop/Cxx/class/constructors-typechecker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ let implicit = ImplicitDefaultConstructor()
88

99
let deletedImplicitly = ConstructorWithParam() // expected-error {{missing argument for parameter #1 in call}}
1010

11-
let deletedExplicitly = DefaultConstructorDeleted() // expected-error {{cannot be constructed because it has no accessible initializers}}
11+
let deletedExplicitly = DefaultConstructorDeleted() // expected-error {{missing argument for parameter 'a' in call}}
1212

1313
let withArg = ConstructorWithParam(42)

test/Interop/Cxx/class/synthesized-initializers-silgen.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-swift-frontend -I %S/Inputs -enable-cxx-interop -emit-silgen %s | %FileCheck %s
22

33
import SynthesizedInitializers
4+
import Constructors
45

56
// CHECK-LABEL: sil [ossa] @$s4main18emptyTypeNoArgInityyF : $@convention(thin) () -> ()
67
// CHECK: [[AS:%.*]] = alloc_stack $EmptyStruct
@@ -32,3 +33,12 @@ public func singleMemberTypeNoArgInit() {
3233
public func singleMemberTypeValueInit() {
3334
let i = IntBox(x: 42)
3435
}
36+
37+
// CHECK-LABEL: sil shared [transparent] [serializable] [ossa] @$sSo25DefaultConstructorDeletedV1aABSpys5Int32VG_tcfC : $@convention(method) (UnsafeMutablePointer<Int32>, @thin DefaultConstructorDeleted.Type) -> DefaultConstructorDeleted
38+
// CHECK: bb0([[A:%.*]] : $UnsafeMutablePointer<Int32>
39+
// CHECK-NEXT: [[OUT:%.*]] = struct $DefaultConstructorDeleted ([[A]] : $UnsafeMutablePointer<Int32>)
40+
// CHECK-NEXT: return [[OUT]] : $DefaultConstructorDeleted
41+
// CHECK-LABEL: end sil function '$sSo25DefaultConstructorDeletedV1aABSpys5Int32VG_tcfC'
42+
public func deletedConstructor(a: UnsafeMutablePointer<Int32>) {
43+
let deletedExplicitly = DefaultConstructorDeleted(a: a)
44+
}

0 commit comments

Comments
 (0)