@@ -553,7 +553,15 @@ namespace {
553553 const auto *cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(ClangDecl);
554554 if (!cxxRecordDecl)
555555 return nullptr ;
556- return importer::findCopyConstructor (cxxRecordDecl);
556+ for (auto ctor : cxxRecordDecl->ctors ()) {
557+ if (ctor->isCopyConstructor () &&
558+ // FIXME: Support default arguments (rdar://142414553)
559+ ctor->getNumParams () == 1 &&
560+ ctor->getAccess () == clang::AS_public && !ctor->isDeleted () &&
561+ !ctor->isIneligibleOrNotSelected ())
562+ return ctor;
563+ }
564+ return nullptr ;
557565 }
558566
559567 const clang::CXXConstructorDecl *findMoveConstructor () const {
@@ -611,7 +619,7 @@ namespace {
611619 /* invocation subs*/ SubstitutionMap (), IGF.IGM .Context );
612620 }
613621
614- void emitCopyWithCopyOrMoveConstructor (
622+ void emitCopyWithCopyConstructor (
615623 IRGenFunction &IGF, SILType T,
616624 const clang::CXXConstructorDecl *copyConstructor, llvm::Value *src,
617625 llvm::Value *dest) const {
@@ -621,27 +629,7 @@ namespace {
621629
622630 auto &ctx = IGF.IGM .Context ;
623631 auto *importer = static_cast <ClangImporter *>(ctx.getClangModuleLoader ());
624-
625- if (copyConstructor->isDefaulted () &&
626- copyConstructor->getAccess () == clang::AS_public &&
627- !copyConstructor->isDeleted () &&
628- !copyConstructor->isIneligibleOrNotSelected () &&
629- // Note: we use "doesThisDeclarationHaveABody" here because
630- // that's what "DefineImplicitCopyConstructor" checks.
631- !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));
643- }
644-
632+
645633 auto &diagEngine = importer->getClangSema ().getDiagnostics ();
646634 clang::DiagnosticErrorTrap trap (diagEngine);
647635 auto clangFnAddr =
@@ -821,9 +809,9 @@ namespace {
821809 Address srcAddr, SILType T,
822810 bool isOutlined) const override {
823811 if (auto copyConstructor = findCopyConstructor ()) {
824- emitCopyWithCopyOrMoveConstructor (IGF, T, copyConstructor,
825- srcAddr.getAddress (),
826- destAddr.getAddress ());
812+ emitCopyWithCopyConstructor (IGF, T, copyConstructor,
813+ srcAddr.getAddress (),
814+ destAddr.getAddress ());
827815 return ;
828816 }
829817 StructTypeInfoBase<AddressOnlyCXXClangRecordTypeInfo, FixedTypeInfo,
@@ -836,9 +824,9 @@ namespace {
836824 SILType T, bool isOutlined) const override {
837825 if (auto copyConstructor = findCopyConstructor ()) {
838826 destroy (IGF, destAddr, T, isOutlined);
839- emitCopyWithCopyOrMoveConstructor (IGF, T, copyConstructor,
840- srcAddr.getAddress (),
841- destAddr.getAddress ());
827+ emitCopyWithCopyConstructor (IGF, T, copyConstructor,
828+ srcAddr.getAddress (),
829+ destAddr.getAddress ());
842830 return ;
843831 }
844832 StructTypeInfoBase<AddressOnlyCXXClangRecordTypeInfo, FixedTypeInfo,
@@ -850,15 +838,17 @@ namespace {
850838 SILType T, bool isOutlined,
851839 bool zeroizeIfSensitive) const override {
852840 if (auto moveConstructor = findMoveConstructor ()) {
853- emitCopyWithCopyOrMoveConstructor (IGF, T, moveConstructor,
854- src.getAddress (), dest.getAddress ());
841+ emitCopyWithCopyConstructor (IGF, T, moveConstructor,
842+ src.getAddress (),
843+ dest.getAddress ());
855844 destroy (IGF, src, T, isOutlined);
856845 return ;
857846 }
858847
859848 if (auto copyConstructor = findCopyConstructor ()) {
860- emitCopyWithCopyOrMoveConstructor (IGF, T, copyConstructor,
861- src.getAddress (), dest.getAddress ());
849+ emitCopyWithCopyConstructor (IGF, T, copyConstructor,
850+ src.getAddress (),
851+ dest.getAddress ());
862852 destroy (IGF, src, T, isOutlined);
863853 return ;
864854 }
@@ -872,16 +862,18 @@ namespace {
872862 bool isOutlined) const override {
873863 if (auto moveConstructor = findMoveConstructor ()) {
874864 destroy (IGF, dest, T, isOutlined);
875- emitCopyWithCopyOrMoveConstructor (IGF, T, moveConstructor,
876- src.getAddress (), dest.getAddress ());
865+ emitCopyWithCopyConstructor (IGF, T, moveConstructor,
866+ src.getAddress (),
867+ dest.getAddress ());
877868 destroy (IGF, src, T, isOutlined);
878869 return ;
879870 }
880871
881872 if (auto copyConstructor = findCopyConstructor ()) {
882873 destroy (IGF, dest, T, isOutlined);
883- emitCopyWithCopyOrMoveConstructor (IGF, T, copyConstructor,
884- src.getAddress (), dest.getAddress ());
874+ emitCopyWithCopyConstructor (IGF, T, copyConstructor,
875+ src.getAddress (),
876+ dest.getAddress ());
885877 destroy (IGF, src, T, isOutlined);
886878 return ;
887879 }
0 commit comments