Skip to content

Commit 5024014

Browse files
Merge pull request #67778 from nate-chandler/rdar112792831-4
[IRGen] Exiting terminators don't alloc packs.
2 parents 6076221 + 28a1db8 commit 5024014

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

lib/SIL/IR/SILInstruction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,12 @@ bool SILInstruction::mayRequirePackMetadata() const {
13411341
if (isDeallocatingStack())
13421342
return false;
13431343

1344+
// Terminators that exit the function must not result in pack metadata
1345+
// materialization.
1346+
auto *ti = dyn_cast<TermInst>(this);
1347+
if (ti && ti->isFunctionExiting())
1348+
return false;
1349+
13441350
// Check results and operands for packs. If a pack appears, lowering the
13451351
// instruction might result in pack metadata emission.
13461352
for (auto result : getResults()) {

test/IRGen/pack_metadata_marker_inserter.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ struct S1 {}
2222
struct S2 {}
2323
struct S3 {}
2424

25+
struct GVT<each T> : Error {
26+
}
27+
2528
struct GV<each T> {
2629
var tu: (repeat each T)
2730
}
@@ -143,6 +146,16 @@ entry:
143146
return %retval : $()
144147
}
145148

149+
// CHECK-SIL-LABEL: sil @return_variadic : {{.*}} {
150+
// CHECK-SIL: [[RETVAL:%[^,]+]] = struct
151+
// CHECK-SIL: return [[RETVAL]]
152+
// CHECK-SIL-LABEL: } // end sil function 'return_variadic'
153+
sil @return_variadic : $<each T>() -> GVT<repeat each T> {
154+
entry:
155+
%retval = struct $GVT<repeat each T> ()
156+
return %retval : $GVT<repeat each T>
157+
}
158+
146159
// =============================================================================
147160
// FINISH: Instructions: Apply }}
148161
// =============================================================================
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -pack-metadata-marker-inserter -enable-pack-metadata-stack-promotion=true | %FileCheck %s --check-prefixes CHECK-SIL
2+
3+
// REQUIRES: asserts
4+
5+
sil_stage lowered
6+
7+
import Builtin
8+
9+
protocol Error {}
10+
11+
struct GVT<each T> {
12+
}
13+
14+
// CHECK-SIL-LABEL: sil @throw_variadic : {{.*}} {
15+
// CHECK-SIL: [[ERROR:%[^,]+]] = struct
16+
// CHECK-SIL: throw [[ERROR]]
17+
// CHECK-SIL-LABEL: } // end sil function 'throw_variadic'
18+
sil @throw_variadic : $<each T>() -> ((), @error GVT<repeat each T>) {
19+
entry:
20+
%retval = struct $GVT<repeat each T> ()
21+
throw %retval : $GVT<repeat each T>
22+
}
23+

0 commit comments

Comments
 (0)