Skip to content

Commit 628d111

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 40e372f commit 628d111

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,9 +4029,10 @@ namespace {
40294029
}
40304030
if (selfIdx) {
40314031
func->setSelfIndex(selfIdx.value());
4032-
if (Impl.SwiftContext.LangOpts.hasFeature(
4033-
Feature::AddressableParameters))
4034-
func->getImplicitSelfDecl()->setAddressable();
4032+
if (!dc->getDeclaredInterfaceType()->hasReferenceSemantics() &&
4033+
!importedName.importAsMember())
4034+
func->getAttrs().add(new (Impl.SwiftContext)
4035+
AddressableSelfAttr(true));
40354036
} else {
40364037
func->setStatic();
40374038
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func basicMethods(a: UnsafeMutablePointer<Methods>) -> Int32 {
4242
}
4343

4444
// 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]+}})
45+
// CHECK: [[THIS_PTR1:%.*]] = alloca ptr, align {{4|8}}
46+
// CHECK: [[RESULT:%.*]] = call {{(signext )?}}i32 @{{_ZNK7Methods17SimpleConstMethodEi|"\?SimpleConstMethod@Methods@@QEBAHH@Z"}}(ptr %0, i32 {{%?[0-9]+}})
4747
// CHECK: ret i32 [[RESULT]]
4848
func basicMethodsConst(a: UnsafeMutablePointer<Methods>) -> Int32 {
4949
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)