Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<clang::FunctionDecl>(paramContext) &&
cast<clang::FunctionDecl>(paramContext)->isOverloadedOperator()) &&
!isa<clang::ObjCMethodDecl, clang::ObjCContainerDecl>(paramContext)) {
paramInfo->setAddressable();
}

Expand Down
8 changes: 6 additions & 2 deletions lib/SILGen/SILGenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -454,8 +455,11 @@ template<typename T> class SILGenWitnessTable : public SILWitnessVisitor<T> {
// () -> NSString
// But the first is correct, so make sure we don't mark this witness
// as foreign.
if (dyn_cast_or_null<clang::CXXMethodDecl>(
witness.getDecl()->getClangDecl()))
const auto *clangDecl = witness.getDecl()->getClangDecl();
if (clangDecl &&
(dyn_cast<clang::CXXMethodDecl>(clangDecl) ||
(isa<clang::FunctionDecl>(clangDecl) &&
cast<clang::FunctionDecl>(clangDecl)->isOverloadedOperator())))
newDecl = newDecl.asForeign();
return addMethodImplementation(
requirementRef, getWitnessRef(newDecl, witness), witness);
Expand Down
10 changes: 5 additions & 5 deletions test/Interop/Cxx/class/nonescapable-lifetimebound.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,20 @@ 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
// CHECK: sil [clang View.init] {{.*}} : $@convention(c) () -> @lifetime(immortal) @out View
// 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
Expand Down
2 changes: 0 additions & 2 deletions test/Interop/Cxx/stdlib/use-std-function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/SILGen/opaque_values_cxx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnsafePointer<CUnsignedInt>>, [[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'
Expand Down