Skip to content

Commit 3e36448

Browse files
authored
Merge pull request swiftlang#82855 from jckarter/dont-try-to-address-project-static-properties
SILGen: Don't try to project static stored properties as addressable from their base.
2 parents 210eae4 + 3b98bcb commit 3e36448

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3622,8 +3622,8 @@ SILGenFunction::tryEmitAddressableParameterAsAddress(ArgumentSource &&arg,
36223622
auto vd = cast<VarDecl>(memberStorage);
36233623
// TODO: Is it possible and/or useful for class storage to be
36243624
// addressable?
3625-
if (!vd->getDeclContext()->getInnermostTypeContext()
3626-
->getDeclaredTypeInContext()->getStructOrBoundGenericStruct()) {
3625+
if (!vd->isInstanceMember()
3626+
|| !isa<StructDecl>(vd->getDeclContext())) {
36273627
return notAddressable();
36283628
}
36293629

lib/SILGen/SILGenDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,8 @@ static void deallocateAddressable(SILGenFunction &SGF,
684684
const SILGenFunction::VarLoc::AddressableBuffer::State &state) {
685685
SGF.B.createEndBorrow(l, state.storeBorrow);
686686
SGF.B.createDeallocStack(l, state.allocStack);
687-
if (state.reabstraction) {
687+
if (state.reabstraction
688+
&& !state.reabstraction->getType().isTrivial(SGF.F)) {
688689
SGF.B.createDestroyValue(l, state.reabstraction);
689690
}
690691
}

test/SILGen/82368.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-emit-silgen -disable-availability-checking -verify %s
2+
3+
struct A {
4+
static let a: InlineArray = [1]
5+
6+
static func foo() {
7+
a.span.withUnsafeBufferPointer({ buffer in
8+
print("\(buffer.baseAddress!)")
9+
})
10+
}
11+
}

0 commit comments

Comments
 (0)