diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index af12daf957106..91de6cf22ee6e 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -2724,8 +2724,12 @@ static ParamDecl *getParameterInfo(ClangImporter::Implementation *impl, // C++ types taking a reference might return a reference/pointer to a // subobject of the referenced storage. In those cases we need to prevent the // Swift compiler to pass in a temporary copy to prevent dangling. - if (ASTContext.LangOpts.hasFeature(Feature::AddressableParameters) && - !param->getType().isNull() && param->getType()->isReferenceType()) { + auto paramContext = param->getDeclContext(); + if (!param->getType().isNull() && param->getType()->isLValueReferenceType() && + !swiftParamTy->isForeignReferenceType() && + !(isa(paramContext) && + cast(paramContext)->isOverloadedOperator()) && + !isa(paramContext)) { paramInfo->setAddressable(); } diff --git a/lib/SILGen/SILGenType.cpp b/lib/SILGen/SILGenType.cpp index 78038a71f08d0..f89955564a145 100644 --- a/lib/SILGen/SILGenType.cpp +++ b/lib/SILGen/SILGenType.cpp @@ -38,6 +38,7 @@ #include "swift/SIL/SILVTableVisitor.h" #include "swift/SIL/SILWitnessVisitor.h" #include "swift/SIL/TypeLowering.h" +#include "clang/AST/Decl.h" using namespace swift; using namespace Lowering; @@ -454,8 +455,11 @@ template class SILGenWitnessTable : public SILWitnessVisitor { // () -> NSString // But the first is correct, so make sure we don't mark this witness // as foreign. - if (dyn_cast_or_null( - witness.getDecl()->getClangDecl())) + const auto *clangDecl = witness.getDecl()->getClangDecl(); + if (clangDecl && + (dyn_cast(clangDecl) || + (isa(clangDecl) && + cast(clangDecl)->isOverloadedOperator()))) newDecl = newDecl.asForeign(); return addMethodImplementation( requirementRef, getWitnessRef(newDecl, witness), witness); diff --git a/test/Interop/Cxx/class/nonescapable-lifetimebound.swift b/test/Interop/Cxx/class/nonescapable-lifetimebound.swift index 434380d7e8a99..07df2b9dc00f3 100644 --- a/test/Interop/Cxx/class/nonescapable-lifetimebound.swift +++ b/test/Interop/Cxx/class/nonescapable-lifetimebound.swift @@ -130,9 +130,9 @@ private: MoveOnly moveOnlyId(const MoveOnly& p [[clang::lifetimebound]]); // CHECK: sil [clang makeOwner] {{.*}}: $@convention(c) () -> Owner -// CHECK: sil [clang getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow address_for_deps 0) @owned View -// CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> @lifetime(borrow address_for_deps 0) @owned View -// CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> @lifetime(borrow address_for_deps 0, borrow address_for_deps 1) @owned View +// CHECK: sil [clang getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow address 0) @owned View +// CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> @lifetime(borrow address 0) @owned View +// CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> @lifetime(borrow address 0, borrow address 1) @owned View // CHECK: sil [clang Owner.handOutView] {{.*}} : $@convention(cxx_method) (@in_guaranteed Owner) -> @lifetime(borrow 0) @owned View // CHECK: sil [clang Owner.handOutView2] {{.*}} : $@convention(cxx_method) (View, @in_guaranteed Owner) -> @lifetime(borrow 1) @owned View // CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (View, View) -> @lifetime(copy 0, copy 1) @owned View @@ -140,10 +140,10 @@ MoveOnly moveOnlyId(const MoveOnly& p [[clang::lifetimebound]]); // CHECK: sil [clang OtherView.init] {{.*}} : $@convention(c) (View) -> @lifetime(copy 0) @out OtherView // CHECK: sil [clang returnsImmortal] {{.*}} : $@convention(c) () -> @lifetime(immortal) @owned View // CHECK: sil [clang copyView] {{.*}} : $@convention(c) (View, @lifetime(copy 0) @inout View) -> () -// CHECK: sil [clang getCaptureView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow address_for_deps 0) @owned CaptureView +// CHECK: sil [clang getCaptureView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow address 0) @owned CaptureView // CHECK: sil [clang CaptureView.captureView] {{.*}} : $@convention(cxx_method) (View, @lifetime(copy 0) @inout CaptureView) -> () // CHECK: sil [clang CaptureView.handOut] {{.*}} : $@convention(cxx_method) (@lifetime(copy 1) @inout View, @in_guaranteed CaptureView) -> () -// CHECK: sil [clang NS.getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow address_for_deps 0) @owned View +// CHECK: sil [clang NS.getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow address 0) @owned View // CHECK: sil [clang moveOnlyId] {{.*}} : $@convention(c) (@in_guaranteed MoveOnly) -> @lifetime(borrow {{.*}}0) @out MoveOnly //--- test.swift diff --git a/test/Interop/Cxx/stdlib/use-std-function.swift b/test/Interop/Cxx/stdlib/use-std-function.swift index 42f9b4964924c..ee7814d58c24a 100644 --- a/test/Interop/Cxx/stdlib/use-std-function.swift +++ b/test/Interop/Cxx/stdlib/use-std-function.swift @@ -10,8 +10,6 @@ // libstdc++11 declares a templated constructor of std::function with an rvalue-reference parameter, // which aren't yet supported in Swift. Therefore initializing a std::function from Swift closures // will not work on the platforms that are shipped with this version of libstdc++ (rdar://125816354). -// XFAIL: LinuxDistribution=ubuntu-24.04 -// XFAIL: LinuxDistribution=ubuntu-22.04 // XFAIL: LinuxDistribution=rhel-9.3 // XFAIL: LinuxDistribution=rhel-9.4 // XFAIL: LinuxDistribution=rhel-9.5 diff --git a/test/SILGen/opaque_values_cxx.swift b/test/SILGen/opaque_values_cxx.swift index 5d08e68535e46..641b66c11a6a8 100644 --- a/test/SILGen/opaque_values_cxx.swift +++ b/test/SILGen/opaque_values_cxx.swift @@ -17,7 +17,7 @@ import Cxx // CHECK-LABEL: } // end sil function '$sSo3stdO3__1O0065vectorCUnsignedIntstd__1allocatorCUnsignedInt_dDGIrdqahddCJdFaAjaV3Cxx0B8SequenceSCAgHP13__beginUnsafe11RawIteratorQzyFTW' // CHECK-LABEL: sil {{.*}}[ossa] @$sSo3stdO{{(3__1O)?}}0047___wrap_iterUnsafePointerCUnsignedInt_heCInnaEgaVSQSCSQ2eeoiySbx_xtFZTW : {{.*}} { // CHECK: bb0([[LHS:%[^,]+]] : $std.__1.__wrap_iter>, [[RHS:%[^,]+]] : -// CHECK: [[CALLEE:%[^,]+]] = function_ref @$sSo2eeoiySbSo3stdO{{(3__1O)?}}0047___wrap_iterUnsafePointerCUnsignedInt_heCInnaEgaV_AGtFTO +// CHECK: [[CALLEE:%[^,]+]] = function_ref @_ZNSt3__1eqB8ne{{.*}}IPKjEEbRKNS_11__wrap_iterIT_EES7_ // CHECK: [[EQUAL:%[^,]+]] = apply [[CALLEE]]([[LHS]], [[RHS]]) // CHECK: return [[EQUAL]] // CHECK-LABEL: } // end sil function '$sSo3stdO{{(3__1O)?}}0047___wrap_iterUnsafePointerCUnsignedInt_heCInnaEgaVSQSCSQ2eeoiySbx_xtFZTW'