Skip to content

Commit dd921ad

Browse files
committed
Revert "[cxx-interop] Implicitly defined move constructors"
This reverts commit c3cd993.
1 parent 1e446b4 commit dd921ad

File tree

5 files changed

+33
-84
lines changed

5 files changed

+33
-84
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,13 +3132,14 @@ namespace {
31323132
// instantiate its copy constructor.
31333133
bool isExplicitlyNonCopyable = hasNonCopyableAttr(decl);
31343134

3135+
clang::CXXConstructorDecl *moveCtor = nullptr;
31353136
clang::CXXConstructorDecl *defaultCtor = nullptr;
31363137
if (decl->needsImplicitCopyConstructor() && !isExplicitlyNonCopyable) {
31373138
clangSema.DeclareImplicitCopyConstructor(
31383139
const_cast<clang::CXXRecordDecl *>(decl));
31393140
}
31403141
if (decl->needsImplicitMoveConstructor()) {
3141-
clangSema.DeclareImplicitMoveConstructor(
3142+
moveCtor = clangSema.DeclareImplicitMoveConstructor(
31423143
const_cast<clang::CXXRecordDecl *>(decl));
31433144
}
31443145
if (decl->needsImplicitDefaultConstructor()) {
@@ -3155,13 +3156,20 @@ namespace {
31553156
// Note: we use "doesThisDeclarationHaveABody" here because
31563157
// that's what "DefineImplicitCopyConstructor" checks.
31573158
!declCtor->doesThisDeclarationHaveABody()) {
3158-
if (declCtor->isDefaultConstructor()) {
3159+
if (declCtor->isMoveConstructor()) {
3160+
if (!moveCtor)
3161+
moveCtor = declCtor;
3162+
} else if (declCtor->isDefaultConstructor()) {
31593163
if (!defaultCtor)
31603164
defaultCtor = declCtor;
31613165
}
31623166
}
31633167
}
31643168
}
3169+
if (moveCtor && !decl->isAnonymousStructOrUnion()) {
3170+
clangSema.DefineImplicitMoveConstructor(clang::SourceLocation(),
3171+
moveCtor);
3172+
}
31653173
if (defaultCtor) {
31663174
clangSema.DefineImplicitDefaultConstructor(clang::SourceLocation(),
31673175
defaultCtor);
@@ -3170,8 +3178,7 @@ namespace {
31703178
if (decl->needsImplicitDestructor()) {
31713179
auto dtor = clangSema.DeclareImplicitDestructor(
31723180
const_cast<clang::CXXRecordDecl *>(decl));
3173-
if (!dtor->isDeleted() && !dtor->isIneligibleOrNotSelected())
3174-
clangSema.DefineImplicitDestructor(clang::SourceLocation(), dtor);
3181+
clangSema.DefineImplicitDestructor(clang::SourceLocation(), dtor);
31753182
}
31763183
}
31773184

lib/IRGen/GenStruct.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ namespace {
611611
/*invocation subs*/ SubstitutionMap(), IGF.IGM.Context);
612612
}
613613

614-
void emitCopyWithCopyOrMoveConstructor(
614+
void emitCopyWithCopyConstructor(
615615
IRGenFunction &IGF, SILType T,
616616
const clang::CXXConstructorDecl *copyConstructor, llvm::Value *src,
617617
llvm::Value *dest) const {
@@ -625,21 +625,12 @@ namespace {
625625
if (copyConstructor->isDefaulted() &&
626626
copyConstructor->getAccess() == clang::AS_public &&
627627
!copyConstructor->isDeleted() &&
628-
!copyConstructor->isIneligibleOrNotSelected() &&
629628
// Note: we use "doesThisDeclarationHaveABody" here because
630629
// that's what "DefineImplicitCopyConstructor" checks.
631630
!copyConstructor->doesThisDeclarationHaveABody()) {
632-
assert(!copyConstructor->getParent()->isAnonymousStructOrUnion() &&
633-
"Cannot do codegen of special member functions of anonymous "
634-
"structs/unions");
635-
if (copyConstructor->isCopyConstructor())
636-
importer->getClangSema().DefineImplicitCopyConstructor(
637-
clang::SourceLocation(),
638-
const_cast<clang::CXXConstructorDecl *>(copyConstructor));
639-
else
640-
importer->getClangSema().DefineImplicitMoveConstructor(
641-
clang::SourceLocation(),
642-
const_cast<clang::CXXConstructorDecl *>(copyConstructor));
631+
importer->getClangSema().DefineImplicitCopyConstructor(
632+
clang::SourceLocation(),
633+
const_cast<clang::CXXConstructorDecl *>(copyConstructor));
643634
}
644635

645636
auto &diagEngine = importer->getClangSema().getDiagnostics();
@@ -821,9 +812,9 @@ namespace {
821812
Address srcAddr, SILType T,
822813
bool isOutlined) const override {
823814
if (auto copyConstructor = findCopyConstructor()) {
824-
emitCopyWithCopyOrMoveConstructor(IGF, T, copyConstructor,
825-
srcAddr.getAddress(),
826-
destAddr.getAddress());
815+
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
816+
srcAddr.getAddress(),
817+
destAddr.getAddress());
827818
return;
828819
}
829820
StructTypeInfoBase<AddressOnlyCXXClangRecordTypeInfo, FixedTypeInfo,
@@ -836,9 +827,9 @@ namespace {
836827
SILType T, bool isOutlined) const override {
837828
if (auto copyConstructor = findCopyConstructor()) {
838829
destroy(IGF, destAddr, T, isOutlined);
839-
emitCopyWithCopyOrMoveConstructor(IGF, T, copyConstructor,
840-
srcAddr.getAddress(),
841-
destAddr.getAddress());
830+
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
831+
srcAddr.getAddress(),
832+
destAddr.getAddress());
842833
return;
843834
}
844835
StructTypeInfoBase<AddressOnlyCXXClangRecordTypeInfo, FixedTypeInfo,
@@ -850,15 +841,17 @@ namespace {
850841
SILType T, bool isOutlined,
851842
bool zeroizeIfSensitive) const override {
852843
if (auto moveConstructor = findMoveConstructor()) {
853-
emitCopyWithCopyOrMoveConstructor(IGF, T, moveConstructor,
854-
src.getAddress(), dest.getAddress());
844+
emitCopyWithCopyConstructor(IGF, T, moveConstructor,
845+
src.getAddress(),
846+
dest.getAddress());
855847
destroy(IGF, src, T, isOutlined);
856848
return;
857849
}
858850

859851
if (auto copyConstructor = findCopyConstructor()) {
860-
emitCopyWithCopyOrMoveConstructor(IGF, T, copyConstructor,
861-
src.getAddress(), dest.getAddress());
852+
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
853+
src.getAddress(),
854+
dest.getAddress());
862855
destroy(IGF, src, T, isOutlined);
863856
return;
864857
}
@@ -872,16 +865,18 @@ namespace {
872865
bool isOutlined) const override {
873866
if (auto moveConstructor = findMoveConstructor()) {
874867
destroy(IGF, dest, T, isOutlined);
875-
emitCopyWithCopyOrMoveConstructor(IGF, T, moveConstructor,
876-
src.getAddress(), dest.getAddress());
868+
emitCopyWithCopyConstructor(IGF, T, moveConstructor,
869+
src.getAddress(),
870+
dest.getAddress());
877871
destroy(IGF, src, T, isOutlined);
878872
return;
879873
}
880874

881875
if (auto copyConstructor = findCopyConstructor()) {
882876
destroy(IGF, dest, T, isOutlined);
883-
emitCopyWithCopyOrMoveConstructor(IGF, T, copyConstructor,
884-
src.getAddress(), dest.getAddress());
877+
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
878+
src.getAddress(),
879+
dest.getAddress());
885880
destroy(IGF, src, T, isOutlined);
886881
return;
887882
}

test/Interop/Cxx/stdlib/Inputs/module.modulemap

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,3 @@ module CustomSmartPtr {
9999
requires cplusplus
100100
export *
101101
}
102-
103-
module StdExpected {
104-
header "std-expected.h"
105-
requires cplusplus
106-
export *
107-
}

test/Interop/Cxx/stdlib/Inputs/std-expected.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/Interop/Cxx/stdlib/use-std-expected-typechecker.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)