Skip to content

Commit bed2603

Browse files
martinboehmezoecarver
authored andcommitted
Various changes after merging master:
- Adapt tests to changes that have happened in the meantime (e.g. `HasVirtualBase` is rightly no longer considered loadable) - Don't import copy or move constructors (noticed this because references are now imported correctly, so copy and move constructors suddenly started showing up in the SIL test) - Don't try to define an implicitly-deleted default constructor (this previously broke loadable-types-silgen.swift)
1 parent 5644137 commit bed2603

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,8 +3482,9 @@ namespace {
34823482

34833483
result->setHasUnreferenceableStorage(hasUnreferenceableStorage);
34843484

3485-
if (auto cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(decl)) {
3486-
result->setIsCxxNonTrivial(!cxxRecordDecl->isTriviallyCopyable());
3485+
if (cxxRecordDecl) {
3486+
result->setIsCxxNonTrivial(
3487+
!cxxRecordDecl->isTriviallyCopyable());
34873488

34883489
for (auto ctor : cxxRecordDecl->ctors()) {
34893490
if (ctor->isCopyConstructor() &&
@@ -3518,8 +3519,9 @@ namespace {
35183519
clang::CXXConstructorDecl *ctor =
35193520
clangSema.DeclareImplicitDefaultConstructor(
35203521
const_cast<clang::CXXRecordDecl *>(decl));
3521-
clangSema.DefineImplicitDefaultConstructor(clang::SourceLocation(),
3522-
ctor);
3522+
if (!ctor->isDeleted())
3523+
clangSema.DefineImplicitDefaultConstructor(clang::SourceLocation(),
3524+
ctor);
35233525
}
35243526

35253527
return VisitRecordDecl(decl);
@@ -3898,6 +3900,11 @@ namespace {
38983900

38993901
AbstractFunctionDecl *result = nullptr;
39003902
if (auto *ctordecl = dyn_cast<clang::CXXConstructorDecl>(decl)) {
3903+
// Don't import copy constructor or move constructor -- these will be
3904+
// provided through the value witness table.
3905+
if (ctordecl->isCopyConstructor() || ctordecl->isMoveConstructor())
3906+
return nullptr;
3907+
39013908
DeclName ctorName(Impl.SwiftContext, DeclBaseName::createConstructor(),
39023909
bodyParams);
39033910
result = Impl.createDeclWithClangNode<ConstructorDecl>(

test/Interop/Cxx/class/Inputs/constructors.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ struct ConstructorWithParam {
2121
int x;
2222
};
2323

24+
struct CopyAndMoveConstructor {
25+
CopyAndMoveConstructor(const CopyAndMoveConstructor &) = default;
26+
CopyAndMoveConstructor(CopyAndMoveConstructor &&) = default;
27+
};
28+
2429
struct Base {};
2530

2631
struct ArgType {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ public func createHasVirtualBase() -> HasVirtualBase {
2222
// Swift constructors that return their result indirectly) because the C++
2323
// constructor has explicit access to `this` and may capture it.
2424
//
25-
// ITANIUM_X64: define swiftcc { i8*, i32 } @"$ss20createHasVirtualBaseSo0bcD0VyF"()
25+
// ITANIUM_X64: define swiftcc void @"$ss20createHasVirtualBaseSo0bcD0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret %0)
2626
// ITANIUM_X64-NOT: define
2727
// ITANIUM_X64: call void @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* noalias sret %{{[0-9]+}}, i32 %{{[0-9]+}})
2828
//
29-
// ITANIUM_ARM: define protected swiftcc { i8*, i32 } @"$ss20createHasVirtualBaseSo0bcD0VyF"()
29+
// ITANIUM_ARM: define protected swiftcc void @"$ss20createHasVirtualBaseSo0bcD0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret %0)
3030
// To verify that the thunk is inlined, make sure there's no intervening
3131
// `define`, i.e. the call to the C++ constructor happens in
3232
// createHasVirtualBase(), not some later function.
3333
// ITANIUM_ARM-NOT: define
3434
// Note `this` return type.
3535
// ITANIUM_ARM: call %struct.HasVirtualBase* @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* %{{[0-9]+}}, [1 x i32] %{{[0-9]+}})
3636
//
37-
// MICROSOFT_X64: define dllexport swiftcc { i8*, i32 } @"$ss20createHasVirtualBaseSo0bcD0VyF"()
37+
// MICROSOFT_X64: define dllexport swiftcc void @"$ss20createHasVirtualBaseSo0bcD0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret %0)
3838
// MICROSOFT_X64-NOT: define
3939
// Note `this` return type and implicit "most derived" argument.
4040
// MICROSOFT_X64: call %struct.HasVirtualBase* @"??0HasVirtualBase@@QEAA@UArgType@@@Z"(%struct.HasVirtualBase* %{{[0-9]+}}, i32 %{{[0-9]+}}, i32 1)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
// CHECK-NEXT: init(member: ImplicitDefaultConstructor)
1616
// CHECK-NEXT: }
1717
// CHECK-NEXT: struct DefaultConstructorDeleted {
18+
// CHECK-NEXT: var a: UnsafeMutablePointer<Int32>
1819
// CHECK-NEXT: }
1920
// CHECK-NEXT: struct ConstructorWithParam {
2021
// CHECK-NEXT: var x: Int32
2122
// CHECK-NEXT: init(_ val: Int32)
2223
// CHECK-NEXT: }
24+
// CHECK-NEXT: struct CopyAndMoveConstructor {
25+
// CHECK-NEXT: }
2326
// CHECK-NEXT: struct Base {
2427
// CHECK-NEXT: init()
2528
// CHECK-NEXT: }

0 commit comments

Comments
 (0)