SILGen: Don't try to project static stored properties as addressable from their base.

An oversight from https://github.com/swiftlang/swift/pull/82288. Fixes #82368 / rdar://153837014.
This commit is contained in:
Joe Groff
2025-07-07 14:12:37 -07:00
parent 6e8287c29e
commit 3b98bcb0a3
3 changed files with 15 additions and 3 deletions

View File

@@ -3622,8 +3622,8 @@ SILGenFunction::tryEmitAddressableParameterAsAddress(ArgumentSource &&arg,
auto vd = cast<VarDecl>(memberStorage);
// TODO: Is it possible and/or useful for class storage to be
// addressable?
if (!vd->getDeclContext()->getInnermostTypeContext()
->getDeclaredTypeInContext()->getStructOrBoundGenericStruct()) {
if (!vd->isInstanceMember()
|| !isa<StructDecl>(vd->getDeclContext())) {
return notAddressable();
}

View File

@@ -684,7 +684,8 @@ static void deallocateAddressable(SILGenFunction &SGF,
const SILGenFunction::VarLoc::AddressableBuffer::State &state) {
SGF.B.createEndBorrow(l, state.storeBorrow);
SGF.B.createDeallocStack(l, state.allocStack);
if (state.reabstraction) {
if (state.reabstraction
&& !state.reabstraction->getType().isTrivial(SGF.F)) {
SGF.B.createDestroyValue(l, state.reabstraction);
}
}

11
test/SILGen/82368.swift Normal file
View File

@@ -0,0 +1,11 @@
// RUN: %target-swift-emit-silgen -disable-availability-checking -verify %s
struct A {
static let a: InlineArray = [1]
static func foo() {
a.span.withUnsafeBufferPointer({ buffer in
print("\(buffer.baseAddress!)")
})
}
}