Skip to content

Commit 798621e

Browse files
authored
Merge pull request #84264 from jckarter/trivial-address-only-switch
SILGen: Don't copy_addr [take] trivial address-only values.
2 parents b5ef290 + df8ab6e commit 798621e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5221,7 +5221,9 @@ void SILGenFunction::emitSemanticStore(SILLocation loc,
52215221
assert(!silConv.useLoweredAddresses() ||
52225222
(dest->getType().isAddressOnly(F) == rvalue->getType().isAddress()));
52235223
if (rvalue->getType().isAddress()) {
5224-
B.createCopyAddr(loc, rvalue, dest, IsTake, isInit);
5224+
B.createCopyAddr(loc, rvalue, dest,
5225+
rvalue->getType().isTrivial(F) ? IsNotTake : IsTake,
5226+
isInit);
52255227
} else {
52265228
emitUnloweredStoreOfCopy(B, loc, rvalue, dest, isInit);
52275229
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-emit-silgen -verify -disable-availability-checking %s
2+
3+
public enum StreamYieldResult<let count: Int>: Sendable {
4+
case literal(buffer: InlineArray<count, UInt8>)
5+
case end(buffer: InlineArray<count, UInt8>, endIndex: Int)
6+
7+
public func buffer() -> InlineArray<count, UInt8> {
8+
switch self {
9+
case .literal(let b):
10+
return b
11+
case .end(let b, _):
12+
return b
13+
}
14+
}
15+
}

test/SILGen/variadic-generic-tuples.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public struct Container<each T> {
102102
// Finally, the actual assignment.
103103
// CHECK-NEXT: [[ACCESS:%.*]] = begin_access [modify] [unknown] %1 :
104104
// CHECK-NEXT: [[FIELD:%.*]] = struct_element_addr [[ACCESS]] : $*Container<repeat each T>, #Container.storage
105-
// CHECK-NEXT: copy_addr [take] [[COPY2]] to [[FIELD]] : $*(repeat Stored<each T>)
105+
// CHECK-NEXT: copy_addr [[COPY2]] to [[FIELD]] : $*(repeat Stored<each T>)
106106
// CHECK-NEXT: end_access [[ACCESS]]
107107
// Clean up.
108108
// CHECK-NEXT: dealloc_stack [[COPY2]]

0 commit comments

Comments
 (0)