@@ -611,7 +611,7 @@ namespace {
611611 /* invocation subs*/ SubstitutionMap (), IGF.IGM .Context );
612612 }
613613
614- void emitCopyWithCopyConstructor (
614+ void emitCopyWithCopyOrMoveConstructor (
615615 IRGenFunction &IGF, SILType T,
616616 const clang::CXXConstructorDecl *copyConstructor, llvm::Value *src,
617617 llvm::Value *dest) const {
@@ -625,12 +625,21 @@ namespace {
625625 if (copyConstructor->isDefaulted () &&
626626 copyConstructor->getAccess () == clang::AS_public &&
627627 !copyConstructor->isDeleted () &&
628+ !copyConstructor->isIneligibleOrNotSelected () &&
628629 // Note: we use "doesThisDeclarationHaveABody" here because
629630 // that's what "DefineImplicitCopyConstructor" checks.
630631 !copyConstructor->doesThisDeclarationHaveABody ()) {
631- importer->getClangSema ().DefineImplicitCopyConstructor (
632- clang::SourceLocation (),
633- const_cast <clang::CXXConstructorDecl *>(copyConstructor));
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));
634643 }
635644
636645 auto &diagEngine = importer->getClangSema ().getDiagnostics ();
@@ -812,9 +821,9 @@ namespace {
812821 Address srcAddr, SILType T,
813822 bool isOutlined) const override {
814823 if (auto copyConstructor = findCopyConstructor ()) {
815- emitCopyWithCopyConstructor (IGF, T, copyConstructor,
816- srcAddr.getAddress (),
817- destAddr.getAddress ());
824+ emitCopyWithCopyOrMoveConstructor (IGF, T, copyConstructor,
825+ srcAddr.getAddress (),
826+ destAddr.getAddress ());
818827 return ;
819828 }
820829 StructTypeInfoBase<AddressOnlyCXXClangRecordTypeInfo, FixedTypeInfo,
@@ -827,9 +836,9 @@ namespace {
827836 SILType T, bool isOutlined) const override {
828837 if (auto copyConstructor = findCopyConstructor ()) {
829838 destroy (IGF, destAddr, T, isOutlined);
830- emitCopyWithCopyConstructor (IGF, T, copyConstructor,
831- srcAddr.getAddress (),
832- destAddr.getAddress ());
839+ emitCopyWithCopyOrMoveConstructor (IGF, T, copyConstructor,
840+ srcAddr.getAddress (),
841+ destAddr.getAddress ());
833842 return ;
834843 }
835844 StructTypeInfoBase<AddressOnlyCXXClangRecordTypeInfo, FixedTypeInfo,
@@ -841,17 +850,15 @@ namespace {
841850 SILType T, bool isOutlined,
842851 bool zeroizeIfSensitive) const override {
843852 if (auto moveConstructor = findMoveConstructor ()) {
844- emitCopyWithCopyConstructor (IGF, T, moveConstructor,
845- src.getAddress (),
846- dest.getAddress ());
853+ emitCopyWithCopyOrMoveConstructor (IGF, T, moveConstructor,
854+ src.getAddress (), dest.getAddress ());
847855 destroy (IGF, src, T, isOutlined);
848856 return ;
849857 }
850858
851859 if (auto copyConstructor = findCopyConstructor ()) {
852- emitCopyWithCopyConstructor (IGF, T, copyConstructor,
853- src.getAddress (),
854- dest.getAddress ());
860+ emitCopyWithCopyOrMoveConstructor (IGF, T, copyConstructor,
861+ src.getAddress (), dest.getAddress ());
855862 destroy (IGF, src, T, isOutlined);
856863 return ;
857864 }
@@ -865,18 +872,16 @@ namespace {
865872 bool isOutlined) const override {
866873 if (auto moveConstructor = findMoveConstructor ()) {
867874 destroy (IGF, dest, T, isOutlined);
868- emitCopyWithCopyConstructor (IGF, T, moveConstructor,
869- src.getAddress (),
870- dest.getAddress ());
875+ emitCopyWithCopyOrMoveConstructor (IGF, T, moveConstructor,
876+ src.getAddress (), dest.getAddress ());
871877 destroy (IGF, src, T, isOutlined);
872878 return ;
873879 }
874880
875881 if (auto copyConstructor = findCopyConstructor ()) {
876882 destroy (IGF, dest, T, isOutlined);
877- emitCopyWithCopyConstructor (IGF, T, copyConstructor,
878- src.getAddress (),
879- dest.getAddress ());
883+ emitCopyWithCopyOrMoveConstructor (IGF, T, copyConstructor,
884+ src.getAddress (), dest.getAddress ());
880885 destroy (IGF, src, T, isOutlined);
881886 return ;
882887 }
0 commit comments