Skip to content

Commit 9525aee

Browse files
author
Gabor Horvath
committed
[cxx-interop] Enable addressable-self unconditionally
This was behind a feature flag. Unfortunately, this flag is viral, if the module we consume and the consuming module had inconsistent settings that could lead to deserialization errors. To avoid this, we need to move this out of the flag and apply the attribute unconditionally. This PR moves addressable-self out of the experimental flag and addresses a couple of the fallouts: * This attribute should not be applied to types with reference semantics like foreign reference types or Obj-C classes. * There was a SILGen assertion failure which is solved by pealing off the @lvalue specifier from the type behind a load expression. This fixes part of rdar://155971658
1 parent 46ffc2a commit 9525aee

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4036,9 +4036,13 @@ namespace {
40364036
}
40374037
if (selfIdx) {
40384038
func->setSelfIndex(selfIdx.value());
4039-
if (Impl.SwiftContext.LangOpts.hasFeature(
4040-
Feature::AddressableParameters))
4041-
func->getImplicitSelfDecl()->setAddressable();
4039+
// FIXME: Make this work when SIL Opaque Values are enabled.
4040+
// Currently, addressable parameters and opaque values are at odds.
4041+
if (!dc->getDeclaredInterfaceType()->hasReferenceSemantics() &&
4042+
!importedName.importAsMember() &&
4043+
!Impl.SwiftContext.SILOpts.EnableSILOpaqueValues)
4044+
func->getAttrs().add(new (Impl.SwiftContext)
4045+
AddressableSelfAttr(true));
40424046
} else {
40434047
func->setStatic();
40444048
func->setImportAsStaticMember();

lib/SILGen/SILGenApply.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3717,7 +3717,10 @@ SILGenFunction::tryEmitAddressableParameterAsAddress(ArgumentSource &&arg,
37173717
// Materialize the base outside of the scope of the addressor call,
37183718
// since the returned address may depend on the materialized
37193719
// representation, even if it isn't transitively addressable.
3720-
auto baseTy = lookupExpr->getBase()->getType()->getCanonicalType();
3720+
auto baseTy = lookupExpr->getBase()
3721+
->getType()
3722+
->getWithoutSpecifierType()
3723+
->getCanonicalType();
37213724
ArgumentSource baseArg = prepareAccessorBaseArgForFormalAccess(
37223725
lookupExpr->getBase(), base, baseTy, addressorRef);
37233726

test/ClangImporter/cxx_interop_ir.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// RUN: %target-swiftxx-frontend -module-name cxx_ir -I %S/Inputs/custom-modules -emit-ir -o - -primary-file %s -Xcc -fignore-exceptions | %FileCheck %s
22

3-
// https://github.com/apple/swift/issues/55575
4-
// We can't yet call member functions correctly on Windows.
5-
// XFAIL: OS=windows-msvc
6-
73
import CXXInterop
84

95
// CHECK-LABEL: define hidden swiftcc void @"$s6cxx_ir13indirectUsageyyF"()
@@ -42,8 +38,8 @@ func basicMethods(a: UnsafeMutablePointer<Methods>) -> Int32 {
4238
}
4339

4440
// CHECK-LABEL: define hidden swiftcc i32 @"$s6cxx_ir17basicMethodsConst1as5Int32VSpySo0D0VG_tF"(ptr %0)
45-
// CHECK: [[THIS_PTR1:%.*]] = alloca %TSo7MethodsV, align {{4|8}}
46-
// CHECK: [[RESULT:%.*]] = call {{(signext )?}}i32 @{{_ZNK7Methods17SimpleConstMethodEi|"\?SimpleConstMethod@Methods@@QEBAHH@Z"}}(ptr [[THIS_PTR1]], i32 {{%?[0-9]+}})
41+
// CHECK: [[THIS_PTR1:%.*]] = alloca ptr, align {{4|8}}
42+
// CHECK: [[RESULT:%.*]] = call {{(signext )?}}i32 @{{_ZNK7Methods17SimpleConstMethodEi|"\?SimpleConstMethod@Methods@@QEBAHH@Z"}}(ptr %0, i32 {{%?[0-9]+}})
4743
// CHECK: ret i32 [[RESULT]]
4844
func basicMethodsConst(a: UnsafeMutablePointer<Methods>) -> Int32 {
4945
return a.pointee.SimpleConstMethod(3)

test/Interop/Cxx/class/method/methods-addressable-silgen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public func addressableTest(x: borrowing @_addressable NonTrivialInWrapper, y: i
1717
// CHECK: %{{[0-9]+}} = apply %{{[0-9]+}}([[UNWRAPPED]], %{{[0-9]+}}) : $@convention(cxx_method) (@in_guaranteed NonTrivialInWrapper, @in_guaranteed HasMethods) -> ()
1818
var m2 = HasMethods()
1919
// CHECK: [[ACCESS:%[0-9]+]] = begin_access [modify] [unknown] [[INPUT2]]
20-
// CHECK: %{{[0-9]+}} = apply %32([[ACCESS]], %{{[0-9]+}}) : $@convention(cxx_method) (@inout NonTrivialInWrapper, @in_guaranteed HasMethods) -> ()
20+
// CHECK: %{{[0-9]+}} = apply %{{[0-9]+}}([[ACCESS]], %{{[0-9]+}}) : $@convention(cxx_method) (@inout NonTrivialInWrapper, @in_guaranteed HasMethods) -> ()
2121
// CHECK-NEXT: end_access [[ACCESS]]
2222
m2.nonTrivialTakesRef(&y)
2323
}

0 commit comments

Comments
 (0)